# Enterprise Storage OS (ESOS) Makefile[.in]
# Makefile is generated from Makefile.in via the configure script.
# Please see the README/INSTALL documents for help.

SRC_DIR		:= @src_dir@
BUILD_DIR	:= @build_dir@
WORK_DIR	:= @work_dir@
DIST_FILES_DIR	:= @dist_files_dir@
SOURCES_DIR	:= @sources_dir@
CHROOT_DIR	:= @chroot_dir@
TOOLS_DIR	:= @tools_dir@
INITRAMFS_DIR	:= @initramfs_dir@
MOUNT_DIR	:= @mount_dir@
STAGING_DIR	:= @staging_dir@

QUIET		:= @
SHELL		:= @bash@

WGET		:= @wget@ -t 5
MKDIR		:= @mkdir@ -p
RM		:= @rm@ -rf
TAR		:= @tar@
CP		:= @cp@
FIND		:= @find@
CPIO		:= @cpio@
GZIP		:= @gzip@ -9f
ECHO		:= @echo@
SFDISK		:= @sfdisk@
CAT		:= @cat@
GREP		:= @grep@
DD		:= @dd@
MKFS_VFAT	:= @mkfs_vfat@
MKFS_EXT2	:= @mkfs_ext2@
LN		:= @ln@ -sf
MOUNT		:= @mount@
UMOUNT		:= @umount@
SED		:= @sed@
MKNOD		:= @mknod@
TOUCH		:= @touch@
INSTALL		:= @install@ -c
PATCH		:= @patch@
CHOWN		:= @chown@
CHMOD		:= @chmod@
MD5SUM		:= @md5sum@
SHA256SUM	:= @sha256sum@
SLEEP		:= @sleep@
LOSETUP		:= @losetup@
KPARTX		:= @kpartx@
XARGS		:= @xargs@
ZIP		:= @zip@
XZ		:= @xz@
READLINK	:= @readlink@
STRIP		:= @strip@
BZIP2		:= @bzip2@
GIT		:= @git@
FLOCK		:= @flock@
ZIC		:= @zic@
MV		:= @mv@
RSYNC		:= @rsync@
MKSQUASHFS	:= @mksquashfs@

enable_debug		:= @enable_debug@
enable_gdb		:= @enable_gdb@
enable_valgrind		:= @enable_valgrind@
enable_strace		:= @enable_strace@
enable_nginx		:= @enable_nginx@
enable_python_sql	:= @enable_python_sql@
enable_zfs		:= @enable_zfs@
enable_lessfs		:= @enable_lessfs@
enable_qemu		:= @enable_qemu@
enable_mhvtl		:= @enable_mhvtl@
enable_eio		:= @enable_eio@
enable_btier		:= @enable_btier@
enable_simple_tui	:= @enable_simple_tui@
enable_auto_dhcp	:= @enable_auto_dhcp@
enable_tui_eula		:= @enable_tui_eula@
enable_tui_usage	:= @enable_tui_usage@
enable_login_tui	:= @enable_login_tui@
enable_debug_kernel	:= @enable_debug_kernel@
enable_qla32		:= @enable_qla32@
with_celerity_16_32	:= @with_celerity_16_32@
celerity_16_32_dir	:= $(subst $(CHROOT_DIR),,@celerity_16_32_dir@)
with_atto_scst		:= @with_atto_scst@
atto_scst_dir		:= $(subst $(CHROOT_DIR),,@atto_scst_dir@)
with_ocs_sdk		:= @with_ocs_sdk@
ocs_sdk_dir		:= $(subst $(CHROOT_DIR),,@ocs_sdk_dir@)
with_rapiddisk		:= @with_rapiddisk@
rapiddisk_dir		:= $(subst $(CHROOT_DIR),,@rapiddisk_dir@)
with_uwire		:= @with_uwire@
uwire_dir		:= $(subst $(CHROOT_DIR),,@uwire_dir@)
with_mlnx_ofed		:= @with_mlnx_ofed@
mlnx_ofed_dir		:= $(subst $(CHROOT_DIR),,@mlnx_ofed_dir@)
with_customize_dir	:= @with_customize_dir@
customize_dir		:= @customize_dir@
build_opts		:= @build_opts@
opt_suffix		:= @opt_suffix@

git_branch	:= $(shell if branch="$$($(GIT) --git-dir=$(SRC_DIR)/.git \
		rev-parse --symbolic-full-name --abbrev-ref HEAD 2>&1)"; \
		then echo -n "$$branch"; else echo -n "UNKNOWN"; fi)
git_hash	:= $(shell if hash="$$($(GIT) --git-dir=$(SRC_DIR)/.git \
		rev-parse --short HEAD 2>&1)"; \
		then echo -n "$$hash"; else echo -n "UNKNOWN"; fi)
git_tag		:= $(shell if tag="$$($(GIT) --git-dir=$(SRC_DIR)/.git \
		describe --exact-match --abbrev=0 2>&1)"; \
		then echo -n "$$tag"; else echo -n ""; fi)
rel_name	:= $(git_tag)$(opt_suffix)
dev_name	:= $(git_branch)_$(git_hash)$(opt_suffix)
esos_ver	:= $(if $(git_tag),$(rel_name),$(dev_name))
product		:= Enterprise Storage OS
short_prod	:= ESOS
pkg_name	:= esos
prod_suffix	:= -esos.prod
ifeq ($(enable_debug_kernel),yes)
debug_suffix	:= -esos.debug
endif

dist_files	= $(addprefix $(DIST_FILES_DIR)/, \
		binutils-2.32.tar.xz \
		gcc-9.1.0.tar.xz \
		gmp-6.1.2.tar.xz \
		mpfr-4.0.2.tar.xz \
		mpc-1.1.0.tar.gz \
		linux-5.4.69.tar.xz \
		glibc-2.29.tar.xz \
		tcl-8.6.9.tar.xz \
		expect-5.45.4.tar.xz \
		dejagnu-1.6.2.tar.gz \
		check-0.12.0.tar.gz \
		ncurses-6.1.tar.gz \
		bash-5.0.007.tar.xz \
		bison-3.3.2.tar.xz \
		bzip2-1.0.6.tar.gz \
		coreutils-8.31.tar.xz \
		diffutils-3.7.tar.xz \
		file-5.36.tar.gz \
		findutils-4.6.0.tar.gz \
		gawk-5.0.0.tar.xz \
 		gettext-0.19.8.1.tar.xz \
		grep-3.3.tar.xz \
		gzip-1.10.tar.xz \
		m4-1.4.18.tar.xz \
		make-4.2.1.tar.bz2 \
		patch-2.7.6.tar.xz \
		perl-5.28.2.tar.xz \
		sed-4.7.tar.xz \
		tar-1.32.tar.xz \
		texinfo-6.6.tar.xz \
		util-linux-2.33.2.tar.xz \
		xz-5.2.4.tar.xz \
		pkg-config-0.29.2.tar.gz \
		which-2.21.tar.gz \
		autoconf-2.69.tar.xz \
		automake-1.16.1.tar.xz \
		libtool-2.4.6.tar.xz \
		flex-2.6.4.tar.gz \
		Python-3.6.8.tar.xz \
		cmake-3.14.4.tar.gz \
		ninja-1.9.0.tar.gz \
		meson-0.56.0.tar.gz \
		setuptools-28.6.0.tar.gz \
		Linux-PAM-1.3.1.tar.xz \
		busybox-1.30.1.tar.bz2 \
		grub-2.02.tar.xz \
		sysvinit-2.94.tar.xz \
		vixie-cron-4.1.tar.bz2 \
		libibumad-1.3.10.2.tar.gz \
		libibverbs-1.2.1.tar.gz \
		libcxgb3-1.3.1.tar.gz \
		libcxgb4-1.4.0.tar.gz \
		libi40iw-0.5.227.tar.gz \
		libmlx4-1.2.1.tar.gz \
		libmlx5-1.2.1.tar.gz \
		libmthca-1.0.6.tar.gz \
		libnes-1.1.4.tar.gz \
		libocrdma-1.0.8.tar.gz \
		srptools-1.0.3.tar.gz \
		openssh-8.0p1.tar.gz \
		ssmtp-2.64.tar.bz2 \
		openssl-1.1.1i.tar.gz \
		e2fsprogs-1.45.1.tar.xz \
		zlib-1.2.11.tar.xz \
		lsscsi-030r154.tar.gz \
		sg3_utils-1.44.tar.xz \
		groff-1.22.4.tar.gz \
		qlogic_fw-20190427.tar.gz \
		iniparser-4.1.tar.gz \
		cdk-5.0-20161210.tar.gz \
		scst-3.4.x_r9170.tar.xz \
		kexec-tools-2.0.19.tar.xz \
		drbd-utils-9.8.0.tar.gz \
		lvm2-2_02_184.tar.xz \
		xfsprogs-4.20.0.tar.xz \
		mdadm-4.1.tar.xz \
		parted-3.2.tar.xz \
		libqb-1.0.5.tar.xz \
		pacemaker-1.1.20.tar.xz \
		corosync-2.4.4.tar.gz \
		nss-3.43.tar.gz \
		glib-2.61.0.tar.xz \
		libxml2-2.9.9.tar.gz \
		libxslt-1.1.33.tar.gz \
		crmsh-master_20180520.tar.xz \
		libaio-0.3.111.tar.xz \
		glue-1.0.12.tar.bz2 \
		readline-8.0.tar.gz \
		resource-agents-4.2.0.tar.gz \
		lzo-2.10.tar.gz \
		fuse-2.9.7.tar.gz \
		db-5.3.28.tar.gz \
		fence-agents-4.3.3.tar.gz \
		opensm-3.3.20.tar.gz \
		curl-7.64.1.tar.xz \
		open-fcoe-3.19.tar.gz \
		open-lldp-0.9.46.tar.gz \
		libconfig-1.7.2.tar.gz \
		libnl-1.1.4.tar.gz \
		libpciaccess-0.14.tar.bz2 \
		linux_firmware-20190416.tar.xz \
		dlm-4.0.8.tar.xz \
		sysklogd-new_remote_opt_20190715.tar.xz \
		ipmitool-1.8.18.tar.bz2 \
		less-530.tar.gz \
		irqbalance-1.5.0.tar.gz \
		ethtool-5.0.tar.xz \
		infiniband-diags-1.6.7.tar.gz \
		libibmad-1.3.13.tar.gz \
		perftest-4.4-0.5.tar.xz \
		bcache-tools-1.0.8.tar.gz \
		nrpe-3.2.1.tar.gz \
		thin-provisioning-tools-0.8.1.tar.xz \
		expat-2.2.6.tar.bz2 \
		boost-1.70.0.tar.xz \
		librdmacm-1.1.0.tar.gz \
		sysstat-12.1.4.tar.xz \
		pciutils-3.6.2.tar.xz \
		net-snmp-5.8.tar.xz \
		nut-2.7.4.tar.gz \
		libusb-1.0.22.tar.bz2 \
		libusb_compat-0.1.7.tar.xz \
		freeipmi-1.6.3.tar.gz \
		libgcrypt-1.8.4.tar.bz2 \
		libgpg-error-1.36.tar.bz2 \
		smartmontools-7.0.tar.gz \
		cryptsetup-1.7.5.tar.xz \
		popt-1.16.tar.gz \
		makedumpfile-1.6.7.tar.gz \
		elfutils-0.176.tar.bz2 \
		fio-3.13.tar.xz \
		mtx-1.3.12.tar.gz \
		mt-st-1.3.tar.gz \
		nagios-plugins-2.2.1.tar.gz \
		libedit-20190324-3.1.tar.gz \
		libmcrypt-2.5.8.tar.bz2 \
		nsca-2.9.2.tar.gz \
		btrfs-progs-4.20.2.tar.xz \
		attr-2.4.48.tar.gz \
		acl-2.2.53.tar.gz \
		htop-2.2.0.tar.gz \
		dmidecode-3.2.tar.xz \
		xmlrpc-c-1.39.13.tar.gz \
		stunnel-5.53.tar.gz \
		sudo-1.8.27.tar.gz \
		rsync-3.1.3.tar.gz \
		eudev-3.2.7.tar.gz \
		gperf-3.1.tar.gz \
		multipath-tools-0.8.1.tar.xz \
		json-c-0.13.1-20180305.tar.xz \
		archivemount-0.8.12.tar.gz \
		libarchive-3.3.3.tar.gz \
		rasdaemon-0.6.5.tar.bz2 \
		edac-utils-0.18.tar.gz \
		sysfsutils-2.1.0.tar.gz \
		sqlite-autoconf-3280000.tar.gz \
		iperf2-2.0.13.tar.xz \
		iperf3-3.6.tar.xz \
		libpcap-1.9.0.tar.gz \
		iftop-1.0pre4.tar.gz \
		nmon-16j.tar.xz \
		munin-c-0.0.13.tar.xz \
		open-iscsi-2.1.1.tar.gz \
		open-isns-0.99.tar.gz \
		open-vm-tools-10.3.10-12406962.tar.gz \
		libdnet-1.11.tar.gz \
		libffi-3.2.1.tar.gz \
		openwsman-2.7.0.tar.gz \
		swig-4.0.0.tar.gz \
		userspace-rcu-0.11.0.tar.bz2 \
		tzdata-2019a.tar.xz \
		nvme-cli-1.8.1.tar.gz \
		freetype-2.10.0.tar.bz2 \
		ledmon-0.92.tar.gz \
		nvmetcli-master_20180523.tar.xz \
		bc-1.07.1.tar.gz \
		etckeeper-1.18.10.tar.gz \
		git-2.21.0.tar.xz \
		nfs-utils-2.3.4.tar.xz \
		rpcbind-1.2.5.tar.bz2 \
		libtirpc-1.1.4.tar.bz2 \
		libevent-2.1.8-stable.tar.gz \
		keyutils-1.6.tar.bz2 \
		libnfsidmap-0.26.tar.bz2 \
		hdparm-9.58.tar.gz \
		kbd-2.0.4.tar.xz \
		dosfstools-4.1.tar.xz \
		lsof-4.91.tar.xz \
		blktrace-master_20181015.tar.xz \
		hwloc-2.0.3.tar.bz2 \
		mstflint-4.11.0-3.tar.xz \
		cls_switchtec-4.0.0_5.4_20201211.tar.xz \
		lshw-B.02.18.tar.gz \
		iozone3-487.tar.xz \
		telegraf-1.14.3_linux_amd64.tar.xz \
		sbd-1.4.1.tar.gz \
		screen-4.6.2.tar.gz \
		lftp-4.8.4.tar.xz \
		ndctl-65.tar.gz \
		kmod-26.tar.xz \
		docbook-xsl-nons-1.79.2.tar.bz2 \
		acpid-2.0.31.tar.xz \
		ibutils-1.5.7.tar.gz \
		numactl-2.0.13.tar.gz \
		iowatcher-master_20200318.tar.xz \
		iotop-master_20200318.tar.xz \
		node_exporter-1.0.0.linux-amd64.tar.xz \
		libcap-2.36.tar.gz \
		sedutil-master_20201026.tar.xz \
		squashfs-tools-4.4-git.1.tar.gz \
		win_binaries-20180813.tar.xz)
dist_files_repo	= http://download.esos-project.com/dist_files

# Check if we're chroot'd or not
ifeq ($(shell if [ "`awk '$$5=="/" {print $$1}' </proc/1/mountinfo`" != \
	"`awk '$$5=="/" {print $$1}' </proc/$$PPID/mountinfo`" ]; then \
	echo chroot; fi),chroot)
	in_chroot = yes
else
	in_chroot = no
endif

# Handle variable overrides via customization directory
ifeq ($(in_chroot),no)
  ifeq ($(with_customize_dir),yes)
    include $(customize_dir)/overwrites.mk
  endif
else
  ifeq ($(with_customize_dir),yes)
    include overwrites.mk
  endif
endif

# These targets are required before entering the chroot environment
bootstrap_tgts	:= binutils.pass1 gcc.pass1 gmp mpfr mpc kernel_headers \
		glibc gcc.libstdc++ binutils.pass2 gcc.pass2 tcl expect \
		dejagnu check ncurses bash bison bzip2 coreutils diffutils \
		file findutils gawk gettext grep gzip m4 make patch perl \
		sed tar texinfo util-linux xz pkg-config which autoconf \
		automake libtool flex zlib Python cmake ninja meson \
		setuptools rsync

# All targets which are built/installed in the chroot environment
chroot_tgts	:= kernel_headers.chroot glibc.chroot gcc.chroot \
		esos_kernels.chroot esos_tui.chroot scst.chroot \
		Linux-PAM.chroot busybox.chroot makedumpfile.chroot \
		elfutils.chroot sysvinit.chroot grub.chroot perl.chroot \
		Python.chroot qlogic_fw.chroot scstadmin.chroot \
		openssh.chroot vixie-cron.chroot openssl.chroot zlib.chroot \
		ncurses.chroot e2fsprogs.chroot ssmtp.chroot libibumad.chroot \
		libibverbs.chroot libcxgb3.chroot libcxgb4.chroot \
		libi40iw.chroot libmlx4.chroot libmlx5.chroot libmthca.chroot \
		libnes.chroot libocrdma.chroot srptools.chroot lsscsi.chroot \
		sg3_utils.chroot groff.chroot kexec-tools.chroot \
		iniparser.chroot cdk.chroot lvm2.chroot xfsprogs.chroot \
		drbd-utils.chroot mdadm.chroot parted.chroot opensm.chroot \
		libqb.chroot pacemaker.chroot corosync.chroot nss.chroot \
		glib.chroot libxml2.chroot libxslt.chroot bzip2.chroot \
		crmsh.chroot libaio.chroot glue.chroot readline.chroot \
		resource-agents.chroot lzo.chroot fuse.chroot db.chroot \
		fence-agents.chroot curl.chroot fio.chroot \
		open-fcoe.chroot open-lldp.chroot libconfig.chroot \
		libnl.chroot libpciaccess.chroot linux_firmware.chroot \
		dlm.chroot ipmitool.chroot sysklogd.chroot less.chroot \
		irqbalance.chroot ethtool.chroot infiniband-diags.chroot \
		libibmad.chroot perftest.chroot nrpe.chroot \
		bcache-tools.chroot util-linux.chroot \
		thin-provisioning-tools.chroot expat.chroot \
		boost.chroot librdmacm.chroot sysstat.chroot pciutils.chroot \
		net-snmp.chroot nut.chroot libusb.chroot libusb_compat.chroot \
		freeipmi.chroot libgcrypt.chroot libgpg-error.chroot \
		smartmontools.chroot cryptsetup.chroot popt.chroot mtx.chroot \
		mt-st.chroot nagios-plugins.chroot libedit.chroot \
		libmcrypt.chroot nsca.chroot btrfs-progs.chroot attr.chroot \
		acl.chroot htop.chroot dmidecode.chroot xmlrpc-c.chroot \
		stunnel.chroot sudo.chroot rsync.chroot eudev.chroot \
		gperf.chroot multipath-tools.chroot json-c.chroot \
		archivemount.chroot libarchive.chroot rasdaemon.chroot \
		edac-utils.chroot sysfsutils.chroot sqlite-autoconf.chroot \
		iperf2.chroot iperf3.chroot libpcap.chroot iftop.chroot \
		nmon.chroot munin-c.chroot open-iscsi.chroot open-isns.chroot \
		coreutils.chroot open-vm-tools.chroot libdnet.chroot \
		libffi.chroot openwsman.chroot swig.chroot \
		userspace-rcu.chroot tzdata.chroot nvme-cli.chroot \
		freetype.chroot ledmon.chroot nvmetcli.chroot bc.chroot \
		libtool.chroot etckeeper.chroot git.chroot nfs-utils.chroot \
		rpcbind.chroot libtirpc.chroot libevent.chroot \
		keyutils.chroot libnfsidmap.chroot hdparm.chroot kbd.chroot \
		dosfstools.chroot lsof.chroot blktrace.chroot hwloc.chroot \
		mstflint.chroot lshw.chroot iozone3.chroot telegraf.chroot \
		sbd.chroot screen.chroot lftp.chroot ndctl.chroot \
		kmod.chroot docbook-xsl-nons.chroot acpid.chroot \
		ibutils.chroot tcl.chroot numactl.chroot iowatcher.chroot \
		iotop.chroot node_exporter.chroot libcap.chroot \
		sedutil.chroot squashfs-tools.chroot

# And finally these targets should be built without parallel execution
system_tgts	:= bash.chroot findutils.chroot sed.chroot tar.chroot

# Check if we should enable additional build options
ifeq ($(enable_gdb),yes)
	dist_files += $(addprefix $(DIST_FILES_DIR)/,gdb-8.3.tar.xz)
	chroot_tgts += gdb.chroot
endif
ifeq ($(enable_valgrind),yes)
	dist_files += $(addprefix $(DIST_FILES_DIR)/,valgrind-3.15.0.tar.bz2)
	chroot_tgts += valgrind.chroot
endif
ifeq ($(enable_strace),yes)
	dist_files += $(addprefix $(DIST_FILES_DIR)/,strace-5.1.tar.xz)
	chroot_tgts += strace.chroot
endif
ifeq ($(enable_nginx),yes)
	dist_files += $(addprefix $(DIST_FILES_DIR)/,nginx-1.16.0.tar.gz)
	dist_files += $(addprefix $(DIST_FILES_DIR)/,pcre-8.43.tar.gz)
	chroot_tgts += nginx.chroot
	chroot_tgts += pcre.chroot
endif
ifeq ($(enable_python_sql),yes)
	dist_files += $(addprefix $(DIST_FILES_DIR)/,postgresql-9.6.13.tar.bz2)
	dist_files += $(addprefix $(DIST_FILES_DIR)/,mysql-5.0.96.tar.gz)
	chroot_tgts += postgresql.chroot
	chroot_tgts += mysql.chroot
endif
ifeq ($(enable_zfs),yes)
	dist_files += $(addprefix $(DIST_FILES_DIR)/,zfs-0.8.3.tar.gz)
	chroot_tgts += zfs.chroot
endif
ifeq ($(enable_lessfs),yes)
	dist_files += $(addprefix $(DIST_FILES_DIR)/,lessfs-1.7.0.tar.gz)
	dist_files += $(addprefix $(DIST_FILES_DIR)/,tokyocabinet-1.4.48.tar.gz)
	dist_files += $(addprefix $(DIST_FILES_DIR)/,snappy-1.1.7.tar.gz)
	dist_files += $(addprefix $(DIST_FILES_DIR)/,mhash-0.9.9.9.tar.bz2)
	chroot_tgts += lessfs.chroot
	chroot_tgts += tokyocabinet.chroot
	chroot_tgts += snappy.chroot
	chroot_tgts += mhash.chroot
endif
ifeq ($(enable_qemu),yes)
	dist_files += $(addprefix $(DIST_FILES_DIR)/,qemu-5.2.0.tar.xz)
	dist_files += $(addprefix $(DIST_FILES_DIR)/,pixman-0.40.0.tar.gz)
	dist_files += $(addprefix $(DIST_FILES_DIR)/,libvirt-6.10.0.tar.xz)
	dist_files += $(addprefix $(DIST_FILES_DIR)/,gnutls-3.6.15.tar.xz)
	dist_files += $(addprefix $(DIST_FILES_DIR)/,nettle-3.6.tar.gz)
	dist_files += $(addprefix $(DIST_FILES_DIR)/,yajl-2.1.0.tar.gz)
	chroot_tgts += qemu.chroot
	chroot_tgts += pixman.chroot
	chroot_tgts += libvirt.chroot
	chroot_tgts += gnutls.chroot
	chroot_tgts += nettle.chroot
	chroot_tgts += yajl.chroot
endif
ifeq ($(enable_mhvtl),yes)
	dist_files += $(addprefix $(DIST_FILES_DIR)/,\
	mhvtl-1.5-3_release.tar.gz)
	chroot_tgts += mhvtl.chroot
endif
ifeq ($(enable_eio),yes)
	dist_files += $(addprefix $(DIST_FILES_DIR)/,\
	EnhanceIO-master_20151029.tar.gz)
	chroot_tgts += EnhanceIO.chroot
endif
ifeq ($(enable_btier),yes)
	dist_files += $(addprefix $(DIST_FILES_DIR)/,\
	btier-1.3.11.tar.gz)
	chroot_tgts += btier.chroot
endif
ifeq ($(enable_simple_tui),yes)
	tui_cpp_flags += -DSIMPLE_TUI
endif
ifeq ($(enable_tui_eula),yes)
	tui_cpp_flags += -DEULA_PROMPT
endif
ifeq ($(enable_tui_usage),yes)
	tui_cpp_flags += -DUSAGE_PROMPT
endif
ifeq ($(enable_qla32),yes)
	qla_ini_dir=qla2x00t-32gbit
	qla_dir=qla2x00t-32gbit/qla2x00-target
else
	qla_ini_dir=qla2x00t
	qla_dir=qla2x00t/qla2x00-target
endif
ifeq ($(with_celerity_16_32),yes)
	chroot_tgts += celerity_16_32.chroot
endif
ifeq ($(with_atto_scst),yes)
	chroot_tgts += atto_scst.chroot
endif
ifeq ($(with_ocs_sdk),yes)
	chroot_tgts += ocs_sdk.chroot
endif
ifeq ($(with_uwire),yes)
	chroot_tgts += uwire.chroot
endif
ifeq ($(with_mlnx_ofed),yes)
	chroot_tgts += mlnx_ofed.chroot
endif
ifeq ($(with_rapiddisk),yes)
	dist_files += $(addprefix $(DIST_FILES_DIR)/,jansson-2.12.tar.bz2)
	chroot_tgts += rapiddisk.chroot
	chroot_tgts += jansson.chroot
endif

# Handle additional targets via customization directory
ifeq ($(in_chroot),no)
  ifeq ($(with_customize_dir),yes)
    include $(customize_dir)/addtl_targets.mk
  endif
else
  ifeq ($(with_customize_dir),yes)
    include addtl_targets.mk
  endif
endif

# Common variables used throughout
ifeq ($(in_chroot),yes)
	tgt_src_dir	= $(wildcard /sources/$(basename $(@))-*)
	linux_src	= $(wildcard /sources/linux-*)
	scst_src	= $(wildcard /sources/scst-*)
	gcc_src		= $(wildcard /sources/gcc-*)
	chroot_build	= /build
else
	tgt_src_dir	= $(wildcard $(SOURCES_DIR)/$(basename $(@))-*)
	linux_src	= $(wildcard $(SOURCES_DIR)/linux-*)
	scst_src	= $(wildcard $(SOURCES_DIR)/scst-*)
	gcc_src		= $(wildcard $(SOURCES_DIR)/gcc-*)
	chroot_build	= $(CHROOT_DIR)/build
endif
clean_bootstrap_tgts	:= $(addprefix clean-,$(bootstrap_tgts))
clean_chroot_tgts	:= $(addprefix clean-,$(chroot_tgts))
clean_system_tgts	:= $(addprefix clean-,$(system_tgts))
gcc_ver			= $(subst gcc-,,$(notdir $(gcc_src)))
tarball_src_dirs	= $(addprefix $(SOURCES_DIR)/,$(subst .tar.xz,,\
			$(subst .tar.bz2,,$(subst .tar.gz,,\
			$(notdir $(dist_files))))))
img_file		:= $(BUILD_DIR)/$(pkg_name)-$(esos_ver).img
bz2_img_file		:= $(img_file).bz2
stable_img_file		:= $(BUILD_DIR)/$(pkg_name).img
esos_target		= x86_64-esos-linux-gnu
temp_path		= /tools/bin:/bin:/usr/bin

# This is used in the chroot environment
export PKG_CONFIG_PATH = /usr/lib/pkgconfig:/usr/share/pkgconfig

# A few common canned command sequences
define check_if_root
	$(QUIET) if [ `whoami` != "root" ]; then \
	  $(ECHO) "### Snap! Ya gotta be root for this part..."; \
	  exit 1; \
	fi
endef
define chroot_only
	$(QUIET) if [ "$(in_chroot)" != "yes" ]; then \
	  $(ECHO) "### Target '$(@)' can only be made in a chroot'd shell!"; \
	  exit 1; \
	fi
endef
define no_chroot
	$(QUIET) if [ "$(in_chroot)" = "yes" ]; then \
	  $(ECHO) "### Target '$(@)' cannot be made in a chroot'd shell!"; \
	  exit 1; \
	fi
endef
define apply_pkg_patch
	$(QUIET) if [ ! -d $(tgt_src_dir)/$(notdir $(tgt_src_dir)).patch ]; \
	  then \
	  $(PATCH) -d $(tgt_src_dir) -b \
	  -B $(tgt_src_dir)/$(notdir $(tgt_src_dir)).patch/ -p1 < \
	  $(chroot_build)/misc/$(notdir $(tgt_src_dir)).patch; \
	fi
endef

# Set the PATH variable for default goal or specific targets
ifeq ($(MAKECMDGOALS),)
	export PATH = $(temp_path)
else ifneq ($(filter $(MAKECMDGOALS),bootstrap $(bootstrap_tgts)),)
	export PATH = $(temp_path)
endif


# all - The default goal; complete everything up to bootstrap'ing.
all:
	$(MAKE) -C $(BUILD_DIR) fetch
	$(MAKE) -C $(BUILD_DIR) extract
	$(MAKE) -C $(BUILD_DIR) bootstrap


# clean - Remove chroot directory files and any image/package files.
.PHONY: clean
clean: $(clean_chroot_tgts) $(clean_system_tgts)
	$(QUIET) if $(MOUNT) | $(GREP) $(CHROOT_DIR) > /dev/null 2>&1; then \
	  $(ECHO) "### One or more mounts still exist for chroot!"; \
	  exit 1; \
	fi
	cd $(CHROOT_DIR) && $(FIND) . -maxdepth 1 ! -path "." \
	! -path "./sources" ! -path "./build" ! -path "./tools" \
	-exec $(RM) {} \;
	$(RM) $(TOOLS_DIR)/lib/gcc/x86_64-pc-linux-gnu/$(gcc_ver)/specs
	$(RM) $(chroot_build)/*
	$(RM) $(INITRAMFS_DIR)/*
	$(RM) $(SOURCES_DIR)/*
	$(RM) $(BUILD_DIR)/VERSION
	$(RM) $(BUILD_DIR)/dist_*.txt
	$(RM) $(BUILD_DIR)/$(pkg_name)-*.zip
	$(RM) $(BUILD_DIR)/$(pkg_name)-*.img
	$(RM) $(BUILD_DIR)/$(pkg_name)-*.img.bz2
	$(RM) $(BUILD_DIR)/$(pkg_name)-*.iso
	$(RM) $(BUILD_DIR)/$(pkg_name).img
	$(RM) $(BUILD_DIR)/ChangeLog-*.txt
	$(QUIET) $(ECHO) && $(ECHO)
	$(QUIET) $(ECHO) "### Successfully cleaned the chroot structure!"
	$(QUIET) $(ECHO) && $(ECHO)
	$(QUIET) $(ECHO) "### Run './configure' and 'make all' before" \
	"building again..."

$(clean_chroot_tgts):: target = $(subst clean-,,$(@))
$(clean_chroot_tgts)::
	$(RM) $(chroot_build)/$(target)

$(clean_system_tgts):: target = $(subst clean-,,$(@))
$(clean_system_tgts)::
	$(RM) $(chroot_build)/$(target)

clean-esos_tui.chroot::
	$(QUIET) if [ -f "$(chroot_build)/tui/Makefile" ]; then \
	  $(MAKE) --directory=$(chroot_build)/tui clean; \
	fi


# clean_bootstrap - Remove bootstrap target files and extracted sources.
.PHONY: clean_bootstrap
clean_bootstrap: $(clean_bootstrap_tgts)
	$(RM) $(BUILD_DIR)/chroot_build.sh
	$(RM) $(WORK_DIR)/kernel_headers
	$(RM) $(WORK_DIR)/binutils-build
	$(RM) $(WORK_DIR)/gcc-build
	$(RM) $(WORK_DIR)/glibc-build
	$(RM) $(WORK_DIR)/libstdc++-build

$(clean_bootstrap_tgts):: target = $(subst clean-,,$(@))
$(clean_bootstrap_tgts)::
	$(RM) $(BUILD_DIR)/$(target)


# distclean - Remove everything including build configuration settings.
.PHONY: distclean
distclean: clean clean_bootstrap
	$(RM) $(WORK_DIR)
	$(RM) $(SRC_DIR)/autom4te.cache
	$(RM) $(BUILD_DIR)/config.status
	$(RM) $(BUILD_DIR)/configure
	$(RM) $(BUILD_DIR)/config.log
	$(RM) $(BUILD_DIR)/Makefile


# fetch - Grab all required packages from distribution file repositories.
fetch: $(dist_files) ;

$(dist_files):
	$(QUIET) $(ECHO) "### Fetching $(@)"
	$(WGET) -P $(DIST_FILES_DIR) $(dist_files_repo)/$(notdir $(@))
	$(QUIET) cd $(DIST_FILES_DIR) && \
	if ! $(GREP) $(notdir $(@)) $(SRC_DIR)/CHECKSUM.MD5 | \
	  $(MD5SUM) -c -; then \
	  $(RM) $(@); \
	  exit 1; \
	fi
	$(QUIET) cd $(DIST_FILES_DIR) && \
	if ! $(GREP) $(notdir $(@)) $(SRC_DIR)/CHECKSUM.SHA256 | \
	  $(SHA256SUM) -c -; then \
	  $(RM) $(@); \
	  exit 1; \
	fi
	$(QUIET) $(ECHO)


# extract - Extract all of the previously downloaded packages/archives.
extract: fetch $(tarball_src_dirs) ;

$(tarball_src_dirs): src_file = $(wildcard $(DIST_FILES_DIR)/$(notdir $(@)).*)
$(tarball_src_dirs):
	$(QUIET) $(ECHO) "### Extracting $(notdir $(src_file))"
	$(QUIET) $(MKDIR) $(SOURCES_DIR)
	$(QUIET) if [ "$(suffix $(src_file))" = ".gz" ]; then \
	  $(TAR) xfz $(src_file) -C $(SOURCES_DIR); \
	elif [ "$(suffix $(src_file))" = ".bz2" ]; then \
	  $(TAR) xfj $(src_file) -C $(SOURCES_DIR); \
	elif [ "$(suffix $(src_file))" = ".xz" ]; then \
	  $(TAR) xfJ $(src_file) -C $(SOURCES_DIR); \
	else \
	  $(ECHO) "### Unhandled file extension: $(suffix $(src_file))"; \
	  exit 1; \
	fi


# symlink - Creates the symbolic link in "/" for the tools directory.
.PHONY: symlink
symlink:
	$(call no_chroot)
	$(QUIET) if [ -e "/tools" ] && [ ! -L "/tools" ]; then \
	  $(ECHO) "### The path /tools exists but isn't a symbolic link!"; \
	  exit 1; \
	elif [ -L "/tools" ] && \
	  [ "$$($(READLINK) -f /tools)" = "$(TOOLS_DIR)" ]; then \
	  :; \
	else \
	  if [ `whoami` != "root" ]; then \
	    $(ECHO) "### Snap! Ya gotta be root for this part..."; \
	    exit 1; \
	  fi; \
	  $(RM) /tools; \
	  $(LN) -v $(TOOLS_DIR) /tools; \
	fi


# bootstrap - Configure/compile/build the packages for chroot'ing.
.PHONY: bootstrap
bootstrap: symlink $(bootstrap_tgts)
	$(CP) $(BUILD_DIR)/Makefile $(chroot_build)/
	$(CP) -Rp $(SRC_DIR)/misc $(SRC_DIR)/tui $(chroot_build)/
	$(ECHO) -n "$(if $(build_opts),$(build_opts),N/A)" > \
	$(chroot_build)/build_opts
	$(ECHO) -n "$(esos_ver)" > $(chroot_build)/esos_ver
	$(ECHO) -n "$(git_branch)" > $(chroot_build)/git_branch
	$(CP) /etc/passwd /etc/group /etc/resolv.conf $(CHROOT_DIR)/etc/
	$(QUIET) for i in bash cat dd echo ln pwd rm stty; do \
	  if [ ! -e "$(CHROOT_DIR)/bin/$$i" ]; then \
	    $(LN) -v /tools/bin/$$i $(CHROOT_DIR)/bin; \
	  fi; \
	done
	$(QUIET) for i in install perl env; do \
	  if [ ! -e "$(CHROOT_DIR)/usr/bin/$$i" ]; then \
	    $(LN) -v /tools/bin/$$i $(CHROOT_DIR)/usr/bin; \
	  fi; \
	done
	$(QUIET) for i in libgcc_s.so libgcc_s.so.1 libstdc++.a \
	  libstdc++.so libstdc++.so.6; do \
	  if [ ! -e "$(CHROOT_DIR)/usr/lib/$$i" ]; then \
	    $(LN) -v /tools/lib/$$i $(CHROOT_DIR)/usr/lib; \
	  fi; \
	done
	$(QUIET) if [ ! -e "$(CHROOT_DIR)/usr/lib/libstdc++.la" ]; then \
	  $(SED) 's/tools/usr/' /tools/lib/libstdc++.la > \
	  $(CHROOT_DIR)/usr/lib/libstdc++.la; \
	fi
	$(QUIET) if [ ! -e "$(CHROOT_DIR)/bin/sh" ]; then \
	  $(LN) -v bash $(CHROOT_DIR)/bin/sh; \
	fi
	$(ECHO) -e "#!/bin/sh\ncleanup() {\n    make post_chroot\n}\n\
	trap cleanup EXIT\nmake pre_chroot\nchroot \
	--userspec=$(shell id -u):$(shell id -g) \
	\"$(CHROOT_DIR)\" /build/build_all.sh \
	\$$@\nexit \$$?" > \
	$(BUILD_DIR)/chroot_build.sh
	$(CHMOD) +x $(BUILD_DIR)/chroot_build.sh
	$(ECHO) -e "#!/bin/sh\n/tools/bin/env -i\nexport HOME=/\n\
	export TERM=$$TERM\nexport PS1='\u:\w\$$ '\n\
	export PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin\n\
	export LC_ALL=C\n\
	export CFLAGS=\"-Os\"\n\
	export CXXFLAGS=\"-Os\"\n\
	/tools/bin/make \$$@ -C /build build" > \
	$(chroot_build)/build_all.sh
	$(CHMOD) +x $(chroot_build)/build_all.sh

binutils.pass1:
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call no_chroot)
	$(RM) $(WORK_DIR)/binutils-build
	$(MKDIR) $(WORK_DIR)/binutils-build
	cd $(WORK_DIR)/binutils-build && \
	$(tgt_src_dir)/configure --prefix=/tools --with-sysroot=$(CHROOT_DIR) \
	--with-lib-path=/tools/lib --target=$(esos_target) --disable-nls \
	--disable-werror
	$(MAKE) --directory=$(WORK_DIR)/binutils-build
	$(MAKE) --directory=$(WORK_DIR)/binutils-build install
	$(LN) -v lib /tools/lib64
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

gcc.pass1: binutils.pass1 gmp mpfr mpc
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call no_chroot)
	for file in $(tgt_src_dir)/gcc/config/{linux,i386/linux{,64}}.h; do \
	  $(CP) -uv $$file{,.orig}; \
	  $(SED) -e 's@/lib\(64\)\?\(32\)\?/ld@/tools&@g' \
	  -e 's@/usr@/tools@g' $$file.orig > $$file; \
	  $(ECHO) -e "#undef STANDARD_STARTFILE_PREFIX_1\n"\
	  "#undef STANDARD_STARTFILE_PREFIX_2\n"\
	  "#define STANDARD_STARTFILE_PREFIX_1 \"/tools/lib/\"\n"\
	  "#define STANDARD_STARTFILE_PREFIX_2 \"\"" >> $$file; \
	  $(TOUCH) $$file.orig; \
	done
	$(SED) -e '/m64=/s/lib64/lib/' -i.orig \
	$(tgt_src_dir)/gcc/config/i386/t-linux64
	$(RM) $(WORK_DIR)/gcc-build
	$(MKDIR) $(WORK_DIR)/gcc-build
	cd $(WORK_DIR)/gcc-build && $(tgt_src_dir)/configure \
	--target=$(esos_target) --prefix=/tools --with-glibc-version=2.11 \
	--with-sysroot=$(CHROOT_DIR) --with-newlib --without-headers \
	--with-local-prefix=/tools \
	--with-native-system-header-dir=/tools/include --disable-nls \
	--disable-shared --disable-multilib --disable-decimal-float \
	--disable-threads --disable-libatomic --disable-libgomp \
	--disable-libmpx --disable-libquadmath --disable-libssp \
	--disable-libvtv --disable-libstdcxx --enable-languages=c,c++
	$(MAKE) --directory=$(WORK_DIR)/gcc-build
	$(MAKE) --directory=$(WORK_DIR)/gcc-build install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

gmp:
	$(QUIET) $(ECHO) "### Building $(@)"
	$(QUIET) if [ ! -h $(gcc_src)/gmp ]; then \
	  $(LN) -v ../$(notdir $(tgt_src_dir)) $(gcc_src)/gmp; \
	fi
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

mpfr:
	$(QUIET) $(ECHO) "### Building $(@)"
	$(QUIET) if [ ! -h $(gcc_src)/mpfr ]; then \
	  $(LN) -v ../$(notdir $(tgt_src_dir)) $(gcc_src)/mpfr; \
	fi
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

mpc:
	$(QUIET) $(ECHO) "### Building $(@)"
	$(QUIET) if [ ! -h $(gcc_src)/mpc ]; then \
	  $(LN) -v ../$(notdir $(tgt_src_dir)) $(gcc_src)/mpc; \
	fi
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

kernel_headers: gcc.pass1
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call no_chroot)
	$(MKDIR) $(WORK_DIR)/kernel_headers
	$(MAKE) --directory=$(linux_src) mrproper
	$(MAKE) --directory=$(linux_src) \
	INSTALL_HDR_PATH="$(WORK_DIR)/kernel_headers" headers_install
	$(CP) -rv $(WORK_DIR)/kernel_headers/include/* $(TOOLS_DIR)/include/
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

glibc: binutils.pass1 gcc.pass1 kernel_headers
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call no_chroot)
	$(RM) $(WORK_DIR)/glibc-build
	$(MKDIR) $(WORK_DIR)/glibc-build
	cd $(WORK_DIR)/glibc-build && \
	$(tgt_src_dir)/configure --prefix=/tools --host=$(esos_target) \
	--build=$$($(tgt_src_dir)/scripts/config.guess) \
	--enable-kernel=3.2 --with-headers=/tools/include
	$(MAKE) --directory=$(WORK_DIR)/glibc-build
	$(MAKE) --directory=$(WORK_DIR)/glibc-build install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

gcc.libstdc++: glibc
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call no_chroot)
	$(RM) $(WORK_DIR)/libstdc++-build
	$(MKDIR) $(WORK_DIR)/libstdc++-build
	cd $(WORK_DIR)/libstdc++-build && \
	$(tgt_src_dir)/libstdc++-v3/configure --host=$(esos_target) \
	--prefix=/tools --disable-multilib --disable-nls \
	--disable-libstdcxx-threads --disable-libstdcxx-pch \
	--with-gxx-include-dir=/tools/$(esos_target)/include/c++/$(gcc_ver)
	$(MAKE) --directory=$(WORK_DIR)/libstdc++-build
	$(MAKE) --directory=$(WORK_DIR)/libstdc++-build \
	install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

binutils.pass2: gcc.libstdc++
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call no_chroot)
	$(RM) $(WORK_DIR)/binutils-build
	$(MKDIR) $(WORK_DIR)/binutils-build
	cd $(WORK_DIR)/binutils-build && CC=$(esos_target)-gcc \
	AR=$(esos_target)-ar RANLIB=$(esos_target)-ranlib \
	$(tgt_src_dir)/configure --prefix=/tools --disable-nls \
	--disable-werror --with-lib-path=/tools/lib --with-sysroot
	$(MAKE) --directory=$(WORK_DIR)/binutils-build
	$(MAKE) --directory=$(WORK_DIR)/binutils-build install
	$(MAKE) --directory=$(WORK_DIR)/binutils-build/ld clean
	$(MAKE) --directory=$(WORK_DIR)/binutils-build/ld \
	LIB_PATH=/usr/lib:/lib
	$(CP) -f $(WORK_DIR)/binutils-build/ld/ld-new /tools/bin/
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

gcc.pass2: binutils.pass2 gmp mpfr mpc
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call no_chroot)
	$(CAT) $(tgt_src_dir)/gcc/limitx.h $(tgt_src_dir)/gcc/glimits.h \
	$(tgt_src_dir)/gcc/limity.h > `dirname $$($(esos_target)-gcc \
	-print-libgcc-file-name)`/include-fixed/limits.h
	for file in $(tgt_src_dir)/gcc/config/{linux,i386/linux{,64}}.h; do \
	  $(CP) -uv $$file{,.orig}; \
	  $(SED) -e 's@/lib\(64\)\?\(32\)\?/ld@/tools&@g' \
	  -e 's@/usr@/tools@g' $$file.orig > $$file; \
	  $(ECHO) -e "#undef STANDARD_STARTFILE_PREFIX_1\n"\
	  "#undef STANDARD_STARTFILE_PREFIX_2\n"\
	  "#define STANDARD_STARTFILE_PREFIX_1 \"/tools/lib/\"\n"\
	  "#define STANDARD_STARTFILE_PREFIX_2 \"\"" >> $$file; \
	  $(TOUCH) $$file.orig; \
	done
	$(SED) -e '/m64=/s/lib64/lib/' -i.orig \
	$(tgt_src_dir)/gcc/config/i386/t-linux64
	$(RM) $(WORK_DIR)/gcc-build
	$(MKDIR) $(WORK_DIR)/gcc-build
	cd $(WORK_DIR)/gcc-build && CC=$(esos_target)-gcc \
	CXX=$(esos_target)-g++ AR=$(esos_target)-ar \
	RANLIB=$(esos_target)-ranlib \
	$(tgt_src_dir)/configure --prefix=/tools --with-local-prefix=/tools \
	--with-native-system-header-dir=/tools/include \
	--enable-languages=c,c++ --disable-libstdcxx-pch --disable-multilib \
	--disable-bootstrap --disable-libgomp
	$(MAKE) --directory=$(WORK_DIR)/gcc-build
	$(MAKE) --directory=$(WORK_DIR)/gcc-build install
	$(LN) -v gcc /tools/bin/cc
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

tcl: make
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call no_chroot)
	cd $(tgt_src_dir)/unix && ./configure --prefix=/tools
	$(MAKE) --directory=$(tgt_src_dir)/unix
	$(MAKE) --directory=$(tgt_src_dir)/unix install
	$(CHMOD) -v u+w /tools/lib/libtcl8.6.so
	$(MAKE) --directory=$(tgt_src_dir)/unix install-private-headers
	$(LN) -v tclsh8.6 /tools/bin/tclsh
	$(RM) $(tgt_src_dir)
	$(MAKE) --directory=$(BUILD_DIR) extract
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

expect: make tcl
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call no_chroot)
	$(CP) -v $(tgt_src_dir)/configure{,.orig}
	$(SED) 's:/usr/local/bin:/bin:' $(tgt_src_dir)/configure.orig > \
	$(tgt_src_dir)/configure
	cd $(tgt_src_dir) && ./configure --prefix=/tools \
	--with-tcl=/tools/lib --with-tclinclude=/tools/include
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) SCRIPTS="" install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

dejagnu: make expect
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call no_chroot)
	cd $(tgt_src_dir) && ./configure --prefix=/tools
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

check: make
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call no_chroot)
	cd $(tgt_src_dir) && PKG_CONFIG= ./configure \
	--prefix=/tools
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

ncurses: make
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call no_chroot)
	$(SED) -i 's/mawk//' $(tgt_src_dir)/configure
	cd $(tgt_src_dir) && ./configure --prefix=/tools \
	--with-shared --without-debug --without-ada --enable-widec \
	--enable-overwrite
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(MAKE) --directory=$(tgt_src_dir) distclean
	$(LN) -v libncursesw.so /tools/lib/libncurses.so
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

bash: make
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call no_chroot)
	cd $(tgt_src_dir) && ./configure --prefix=/tools \
	--without-bash-malloc
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(MAKE) --directory=$(tgt_src_dir) distclean
	$(LN) -v bash /tools/bin/sh
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

bison: make m4
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call no_chroot)
	cd $(tgt_src_dir) && M4=/tools/bin/m4 ./configure --prefix=/tools
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

bzip2: make
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call no_chroot)
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) PREFIX=/tools install
	$(MAKE) --directory=$(tgt_src_dir) clean
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

coreutils: make perl
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call no_chroot)
	cd $(tgt_src_dir) && FORCE_UNSAFE_CONFIGURE=1 ./configure \
	--prefix=/tools --enable-install-program=hostname
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(MAKE) --directory=$(tgt_src_dir) distclean
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

diffutils: make
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call no_chroot)
	cd $(tgt_src_dir) && ./configure --prefix=/tools
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

file: make
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call no_chroot)
	cd $(tgt_src_dir) && ./configure --prefix=/tools
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

findutils: make
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call no_chroot)
	$(QUIET) if ! $(GREP) -q _IO_IN_BACKUP \
	  $(tgt_src_dir)/gl/lib/stdio-impl.h; then \
	  $(SED) -i 's/IO_ftrylockfile/IO_EOF_SEEN/' \
	  $(tgt_src_dir)/gl/lib/*.c; \
	  $(ECHO) "#define _IO_IN_BACKUP 0x100" >> \
	  $(tgt_src_dir)/gl/lib/stdio-impl.h; \
	  $(SED) -i '/unistd/a #include <sys/sysmacros.h>' \
	  $(tgt_src_dir)/gl/lib/mountlist.c; \
	fi
	cd $(tgt_src_dir) && ./configure --prefix=/tools
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

gawk: make
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call no_chroot)
	cd $(tgt_src_dir) && ./configure --prefix=/tools
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

gettext: make
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call no_chroot)
	cd $(tgt_src_dir)/gettext-tools && EMACS="no" \
	./configure --prefix=/tools --disable-shared
	$(MAKE) --directory=$(tgt_src_dir)/gettext-tools/gnulib-lib
	$(MAKE) --directory=$(tgt_src_dir)/gettext-tools/intl pluralx.c
	$(MAKE) --directory=$(tgt_src_dir)/gettext-tools/src msgfmt
	$(MAKE) --directory=$(tgt_src_dir)/gettext-tools/src msgmerge
	$(MAKE) --directory=$(tgt_src_dir)/gettext-tools/src xgettext
	$(CP) -v $(tgt_src_dir)/gettext-tools/src/{msgfmt,msgmerge,xgettext} \
	/tools/bin/
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

grep: make
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call no_chroot)
	cd $(tgt_src_dir) && ./configure --prefix=/tools
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

gzip: make
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call no_chroot)
	cd $(tgt_src_dir) && ./configure --prefix=/tools
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

m4: make
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call no_chroot)
	$(QUIET) if ! $(GREP) -q _IO_IN_BACKUP \
	  $(tgt_src_dir)/lib/stdio-impl.h; then \
	  $(SED) -i 's/IO_ftrylockfile/IO_EOF_SEEN/' $(tgt_src_dir)/lib/*.c; \
	  $(ECHO) "#define _IO_IN_BACKUP 0x100" >> \
	  $(tgt_src_dir)/lib/stdio-impl.h; \
	fi
	cd $(tgt_src_dir) && ./configure --prefix=/tools
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

make: gcc.pass2
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call no_chroot)
	$(QUIET) if $(GREP) -q 'defined __alloca && !defined __GNU_LIBRARY__' \
	  $(tgt_src_dir)/glob/glob.c; then \
	  $(SED) -i '211,217 d; 219,229 d; 232 d' $(tgt_src_dir)/glob/glob.c; \
	fi
	cd $(tgt_src_dir) && ./configure --prefix=/tools --without-guile
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

patch: make
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call no_chroot)
	cd $(tgt_src_dir) && ./configure --prefix=/tools
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

perl: make
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call no_chroot)
	cd $(tgt_src_dir) && sh Configure -des -Dprefix=/tools \
	-Dlibs=-lm -Uloclibpth -Ulocincpth
	$(MAKE) --directory=$(tgt_src_dir)
	$(CP) -v $(tgt_src_dir)/perl \
	$(tgt_src_dir)/cpan/podlators/scripts/pod2man /tools/bin/
	$(MKDIR) -v /tools/lib/perl5/5.28.2
	$(CP) -Rfv $(tgt_src_dir)/lib/* /tools/lib/perl5/5.28.2/
	$(RM) $(tgt_src_dir)
	$(MAKE) --directory=$(BUILD_DIR) extract
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

sed: make
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call no_chroot)
	cd $(tgt_src_dir) && ./configure --prefix=/tools
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(MAKE) --directory=$(tgt_src_dir) distclean
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

tar: make
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call no_chroot)
	cd $(tgt_src_dir) && FORCE_UNSAFE_CONFIGURE=1 ./configure \
	--prefix=/tools
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(MAKE) --directory=$(tgt_src_dir) distclean
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

texinfo: make perl
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call no_chroot)
	cd $(tgt_src_dir) && ./configure --prefix=/tools
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

util-linux: make
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call no_chroot)
	cd $(tgt_src_dir) && ./configure --prefix=/tools \
	--without-python --disable-makeinstall-chown \
	--without-systemdsystemunitdir --without-ncurses PKG_CONFIG=""
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(MAKE) --directory=$(tgt_src_dir) distclean
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

xz: make
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call no_chroot)
	cd $(tgt_src_dir) && ./configure --prefix=/tools
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

pkg-config: make
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call no_chroot)
	cd $(tgt_src_dir) && ./configure --prefix=/tools \
	--with-internal-glib --disable-host-tool
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

which: make
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call no_chroot)
	cd $(tgt_src_dir) && ./configure --prefix=/tools
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

autoconf: make m4 perl
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call no_chroot)
	cd $(tgt_src_dir) && M4=/tools/bin/m4 ./configure --prefix=/tools
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

automake: make perl autoconf
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call no_chroot)
	cd $(tgt_src_dir) && ./configure --prefix=/tools
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

libtool: make m4 sed
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call no_chroot)
	cd $(tgt_src_dir) && M4=/tools/bin/m4 SED=/tools/bin/sed \
	./configure --prefix=/tools
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(MAKE) --directory=$(tgt_src_dir) distclean
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

flex: make
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call no_chroot)
	$(SED) -i "/math.h/a #include <malloc.h>" $(tgt_src_dir)/src/flexdef.h
	cd $(tgt_src_dir) && HELP2MAN=/tools/bin/true \
	./configure --prefix=/tools
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(LN) -v flex /tools/bin/lex
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

zlib: make
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call no_chroot)
	cd $(tgt_src_dir) && ./configure --prefix=/tools
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(MAKE) --directory=$(tgt_src_dir) distclean
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

Python: make zlib
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call no_chroot)
	$(QUIET) if [ ! -f $(tgt_src_dir)/setup.py.orig ]; then \
	  $(CP) $(tgt_src_dir)/setup.py $(tgt_src_dir)/setup.py.orig; \
	  $(SED) -i '/def add_multiarch_paths/a \        return' \
	  $(tgt_src_dir)/setup.py; \
	fi
	cd $(tgt_src_dir) && ./configure --prefix=/tools --without-ensurepip \
	--without-system-ffi
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(MV) $(tgt_src_dir)/setup.py.orig $(tgt_src_dir)/setup.py
	- $(MAKE) --directory=$(tgt_src_dir) distclean
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

cmake: make
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call no_chroot)
	cd $(tgt_src_dir) && ./bootstrap --prefix=/tools --no-system-libs \
	--verbose -- -DCMAKE_USE_OPENSSL:BOOL=OFF \
	-DCURSES_INCLUDE_PATH:PATH=/tools/include \
	-DGTK2_FONTCONFIG_INCLUDE_DIR:PATH=/tools/include \
	-DGTK2_X11_INCLUDE_DIR:PATH=/tools/include \
	-DQT_HEADERS_DIR:INTERNAL=/tools/include
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

ninja: Python
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call no_chroot)
	cd $(tgt_src_dir) && python3 configure.py --bootstrap
	$(INSTALL) -m 0755 $(tgt_src_dir)/ninja /tools/bin/
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

meson: Python setuptools
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call no_chroot)
	cd $(tgt_src_dir) && python3 setup.py build
	cd $(tgt_src_dir) && python3 setup.py install --root=/
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

setuptools: Python
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call no_chroot)
	cd $(tgt_src_dir) && python3 setup.py install --prefix=/tools
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

rsync: make
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call no_chroot)
	cd $(tgt_src_dir) && ./configure --prefix=/tools
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(MAKE) --directory=$(tgt_src_dir) distclean
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"


# pre_chroot - Setup everything before entering the chroot environment.
.PHONY: pre_chroot
pre_chroot:
	$(call check_if_root)
	$(QUIET) $(MOUNT) -v --bind /dev $(CHROOT_DIR)/dev
	$(QUIET) $(MOUNT) -v --bind /dev/shm $(CHROOT_DIR)/dev/shm
	$(QUIET) $(MOUNT) -vt devpts devpts $(CHROOT_DIR)/dev/pts \
	-o gid=5,mode=620
	$(QUIET) $(MOUNT) -vt proc proc $(CHROOT_DIR)/proc
	$(QUIET) $(MOUNT) -vt sysfs sysfs $(CHROOT_DIR)/sys
	$(QUIET) $(MOUNT) -vt tmpfs tmpfs $(CHROOT_DIR)/run


# build - Configure/compile/build all of the required projects.
.PHONY: build
build: $(chroot_tgts)
	$(MAKE) --jobs=1 $(system_tgts)

kernel_headers.chroot:
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(MKDIR) $(chroot_build)/kernel_headers
	$(MAKE) --directory=$(linux_src) mrproper
	$(MAKE) --directory=$(linux_src) \
	INSTALL_HDR_PATH="$(chroot_build)/kernel_headers" headers_install
	$(MKDIR) /usr/include
	$(CP) -rv $(chroot_build)/kernel_headers/include/* /usr/include/
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

glibc.chroot: gcc_inc_dir = /usr/lib/gcc/x86_64-pc-linux-gnu/$(gcc_ver)/include
glibc.chroot: kernel_headers.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(call apply_pkg_patch)
	$(LN) -v /tools/lib/gcc /usr/lib
	$(LN) -v ../lib/ld-linux-x86-64.so.2 /lib64/ld-lsb-x86-64.so.3
	$(RM) /usr/include/limits.h
	$(RM) $(chroot_build)/glibc-build
	$(MKDIR) $(chroot_build)/glibc-build
	cd $(chroot_build)/glibc-build && \
	CC="gcc -isystem $(gcc_inc_dir) -isystem /usr/include" \
	$(tgt_src_dir)/configure --prefix=/usr --disable-werror \
	--enable-kernel=3.2 --enable-stack-protector=strong \
	--enable-obsolete-rpc --enable-obsolete-nsl libc_cv_slibdir=/lib
	$(MAKE) --directory=$(chroot_build)/glibc-build
	$(TOUCH) /etc/ld.so.conf
	$(SED) '/test-installation/s@$$(PERL)@echo not running@' -i \
	$(tgt_src_dir)/Makefile
	$(MAKE) --directory=$(chroot_build)/glibc-build install
	$(CP) -v $(chroot_build)/misc/glibc.SUPPORTED.locales \
	$(tgt_src_dir)/localedata/SUPPORTED
	$(MAKE) --directory=$(chroot_build)/glibc-build \
	localedata/install-locales
	$(CP) -f /tools/bin/{ld,ld-old}
	$(CP) -f /tools/x86_64-pc-linux-gnu/bin/{ld,ld-old}
	$(CP) -f /tools/bin/{ld-new,ld}
	$(LN) /tools/bin/ld /tools/x86_64-pc-linux-gnu/bin/ld
	$(CC) -dumpspecs | $(SED) -e 's@/tools@@g' \
	-e '/\*startfile_prefix_spec:/{n;s@.*@/usr/lib/ @}' \
	-e '/\*cpp:/{n;s@$$@ -isystem /usr/include@}' > \
	`dirname $$(gcc --print-libgcc-file-name)`/specs
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

gcc.chroot: glibc.chroot gmp mpfr mpc
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(RM) $(chroot_build)/gcc-build
	$(MKDIR) $(chroot_build)/gcc-build
	cd $(chroot_build)/gcc-build && $(tgt_src_dir)/configure \
	--prefix=/usr --disable-multilib --disable-nls --disable-bootstrap \
	--enable-languages=c,c++
	$(MAKE) --directory=$(chroot_build)/gcc-build \
	all-target-libgcc
	$(MAKE) --directory=$(chroot_build)/gcc-build \
	install-target-libgcc
	$(MAKE) --directory=$(chroot_build)/gcc-build \
	all-target-libstdc++-v3
	$(MAKE) --directory=$(chroot_build)/gcc-build \
	install-target-libstdc++-v3
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

esos_kernels.chroot: kernel_ver = $(subst linux-,,$(notdir $(linux_src)))
esos_kernels.chroot: mhvtl_src = $(wildcard /sources/mhvtl-*)
esos_kernels.chroot: eio_src = $(wildcard /sources/EnhanceIO-*)
esos_kernels.chroot: btier_src = $(wildcard /sources/btier-*)
esos_kernels.chroot: zfs_src = $(wildcard /sources/zfs-*)
esos_kernels.chroot: switchtec_src = $(wildcard /sources/cls_switchtec-*)
esos_kernels.chroot: cls_base = $(switchtec_src)/Driver/Switchtec
esos_kernels.chroot: switchtec_kern = switchtec-kernel-release_4.13_to_4.14
esos_kernels.chroot: cls_switchtec = $(cls_base)/$(switchtec_kern)
esos_kernels.chroot: kernel_headers.chroot bc.chroot elfutils.chroot \
	glibc.chroot gcc.chroot util-linux.chroot attr.chroot pciutils.chroot \
	openssl.chroot libcap.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(QUIET) if [ ! -d $(linux_src)/$(notdir $(linux_src)).patch ]; then \
	  $(PATCH) -d $(linux_src) -b \
	  -B $(linux_src)/$(notdir $(linux_src)).patch/ -p1 < \
	  $(chroot_build)/misc/$(notdir $(linux_src)).patch; \
	fi
	$(MAKE) --directory=$(linux_src)/tools/perf \
	EXTRA_CFLAGS="-Wno-stringop-truncation"
	$(INSTALL) -m 0755 $(linux_src)/tools/perf/perf /usr/bin/perf
	$(MAKE) --directory=$(linux_src)/tools/power/x86/\
	x86_energy_perf_policy install
	$(MAKE) --directory=$(linux_src)/tools/power/x86/\
	turbostat install
	$(SED) -i 's/\/bin\/true/true/' \
	$(linux_src)/tools/power/cpupower/Makefile
	$(MAKE) --directory=$(linux_src)/tools/power/cpupower
	$(MAKE) --directory=$(linux_src)/tools/power/cpupower \
	mandir=/usr/share/man install
	$(QUIET) set -e; for i in $(prod_suffix) $(debug_suffix); do \
	  $(ECHO) "### Cleaning source directories..."; \
	  $(MAKE) --directory=$(linux_src) clean; \
	  $(MAKE) --directory=$(linux_src) mrproper; \
	  $(MAKE) --directory=$(linux_src) distclean; \
	  if [ "$(with_mlnx_ofed)" = "yes" ]; then \
	    if [ -e "$(mlnx_ofed_dir)/configure.mk.kernel" ]; then \
	      $(MAKE) --directory=$(mlnx_ofed_dir) clean; \
	    fi; \
	  fi; \
	  $(MAKE) --directory=$(scst_src) KVER=$(kernel_ver)$$i \
	  KDIR=$(linux_src) QLA_INI_DIR=$(qla_ini_dir) QLA_DIR=$(qla_dir) \
	  clean; \
	  $(MAKE) --directory=$(scst_src) KVER=$(kernel_ver)$$i \
	  KDIR=$(linux_src) QLA_INI_DIR=$(qla_ini_dir) QLA_DIR=$(qla_dir) \
	  extraclean; \
	  if [ "$(enable_mhvtl)" = "yes" ]; then \
	    $(MAKE) --directory=$(mhvtl_src)/kernel KDIR=$(linux_src) clean; \
	    $(MAKE) --directory=$(mhvtl_src)/kernel KDIR=$(linux_src) \
	    distclean; \
	  fi; \
	  if [ "$(enable_eio)" = "yes" ]; then \
	    $(MAKE) --directory=$(eio_src)/Driver/enhanceio \
	    KERNEL_TREE=$(linux_src) PWD=$(eio_src)/Driver/enhanceio clean; \
	  fi; \
	  if [ "$(enable_btier)" = "yes" ]; then \
	    $(MAKE) --directory=$(btier_src)/kernel/btier clean; \
	  fi; \
	  if [ "$(with_celerity_16_32)" = "yes" ]; then \
	    $(SED) -i 's/@depmod/#depmod/' \
	    $(celerity_16_32_dir)/src/Makefile; \
	    $(MAKE) --directory=$(celerity_16_32_dir)/src KDIR=$(linux_src) \
	    FULL_KERNEL_VERSION=$(kernel_ver)$$i DRIVER_NAME=celerity16fc \
	    clean; \
	  fi; \
	  if [ "$(with_atto_scst)" = "yes" ]; then \
	    $(SED) -i 's,/usr/local/include/scst,$(scst_src)/scst/include,g' \
	    $(atto_scst_dir)/Makefile; \
	    $(SED) -i 's/-m 0744 -o root -g root/-m 0644/g' \
	    $(atto_scst_dir)/Makefile; \
	    $(SED) -i 's/depmod/#depmod/' \
	    $(atto_scst_dir)/Makefile; \
	    $(SED) -i 's/SUBDIRS=/M=/' \
	    $(atto_scst_dir)/Makefile; \
	    $(MAKE) --directory=$(atto_scst_dir) clean; \
	  fi; \
	  if [ "$(with_ocs_sdk)" = "yes" ]; then \
	    $(MAKE) --directory=$(linux_src) \
	    M=$(ocs_sdk_dir)/driver/linux/ocs_fc_scst clean; \
	  fi; \
	  if [ "$(with_uwire)" = "yes" ]; then \
	    $(MAKE) --directory=$(uwire_dir)/src/network clean; \
	    $(MAKE) --directory=$(uwire_dir)/src/chfcoe/src \
	    CXGB4_SRC_PATH="$(uwire_dir)/src/network/cxgb4" \
	    CSIOSTOR_SRC_PATH="$(uwire_dir)/src/network/csiostor/include" \
	    FIRMWARE_PATH="$(uwire_dir)/src/network/firmware" \
	    KDIR=$(linux_src) clean; \
	  fi; \
	  if [ "$(with_rapiddisk)" = "yes" ]; then \
	    $(MAKE) --directory=$(rapiddisk_dir)/rapiddisk-master/module \
	    clean; \
	  fi; \
	  if [ "$(enable_zfs)" = "yes" ] && [ "$$i" = "$(prod_suffix)" ]; then \
	    if [ -f "$(zfs_src)/Makefile" ]; then \
	      $(MAKE) --directory=$(zfs_src) distclean; \
	    fi; \
	  fi; \
	  $(MAKE) --directory=$(cls_switchtec) KDIR=$(linux_src) \
	  KVER=$(kernel_ver)$$i clean; \
	  if [ "$$i" = "$(prod_suffix)" ]; then \
	    $(SED) 's/CONFIG_LOCALVERSION\=\"\"/CONFIG_LOCALVERSION\=\"$(prod_suffix)\"/' \
	    $(chroot_build)/misc/$(notdir $(linux_src)).config > \
	    $(linux_src)/.config; \
	    $(MAKE) --directory=$(scst_src) KVER=$(kernel_ver)$$i \
	    KDIR=$(linux_src) QLA_INI_DIR=$(qla_ini_dir) QLA_DIR=$(qla_dir) \
	    2perf; \
	  fi; \
	  if [ "$$i" = "$(debug_suffix)" ]; then \
	    $(SED) 's/CONFIG_LOCALVERSION\=\"\"/CONFIG_LOCALVERSION\=\"$(debug_suffix)\"/' \
	    $(chroot_build)/misc/$(notdir $(linux_src)).config > \
	    $(linux_src)/.config; \
	    $(PATCH) -r - -N -d $(linux_src) -p1 < \
	    $(chroot_build)/misc/$(notdir $(linux_src))-debug.patch; \
	    $(MAKE) --directory=$(scst_src) KVER=$(kernel_ver)$$i \
	    KDIR=$(linux_src) QLA_INI_DIR=$(qla_ini_dir) QLA_DIR=$(qla_dir) \
	    2debug; \
	  fi; \
	  if [ "$(with_uwire)" = "yes" ]; then \
	    $(SED) -i 's/CONFIG_CHELSIO_T4\=m/# CONFIG_CHELSIO_T4 is not set/' \
	    $(linux_src)/.config; \
	    $(SED) -i 's/CONFIG_CHELSIO_T4VF\=m/# CONFIG_CHELSIO_T4VF is not set/' \
	    $(linux_src)/.config; \
	    $(SED) -i 's/# CONFIG_FRAME_POINTER is not set/CONFIG_FRAME_POINTER=y/' \
	    $(linux_src)/.config; \
	  fi; \
	  $(ECHO) "### Compiling the Linux kernel..."; \
	  $(MAKE) --directory=$(linux_src); \
	  $(INSTALL) $(linux_src)/arch/x86_64/boot/bzImage \
	  /boot/PRIMARY-bzImage$$i; \
	  $(ECHO) "### Compressing 'vmlinux' for later use..."; \
	  $(XZ) -z -c $(linux_src)/vmlinux > \
	  $(chroot_build)/vmlinux$$i.xz; \
	  $(ECHO) "### Compressing 'System.map' for later use..."; \
	  $(XZ) -z -c $(linux_src)/System.map > \
	  $(chroot_build)/System.map$$i.xz; \
	  $(MAKE) --directory=$(linux_src) modules_install; \
	  if [ "$(with_mlnx_ofed)" = "yes" ]; then \
	    $(ECHO) "### Compiling the Mellanox OFED modules..."; \
	    $(SED) -i '2,$$s/\/bin\///g' $(mlnx_ofed_dir)/configure; \
	    $(SED) -i '2,$$s/\/bin\///g' \
	    $(mlnx_ofed_dir)/compat/config/parallel-build.m4; \
	    $(SED) -i '2,$$s/\/bin\///g' \
	    $(mlnx_ofed_dir)/compat/config/rdma.m4; \
	    $(SED) -i 's/ \/bin\// /g; s/@\/bin\//@/g' \
	    $(mlnx_ofed_dir)/makefile; \
	    cd $(mlnx_ofed_dir)/compat && ./autogen.sh; \
	    cd $(mlnx_ofed_dir) && ./configure --prefix=/usr --with-njobs=10 \
	    --kernel-version=$(kernel_ver)$$i --kernel-sources=$(linux_src) \
	    --with-core-mod --with-ipoib-mod --with-ipoib-cm --with-srp-mod \
	    --with-user_mad-mod --with-user_access-mod --with-addr_trans-mod \
	    --with-mlx5-mod --with-mlx4-mod --with-mlx4_inf-mod \
	    --with-mlx5_inf-mod --with-mlxfw-mod --with-iser-mod \
	    --with-nvmf_host-mod --with-nvmf_target-mod; \
	    $(MAKE) --directory=$(mlnx_ofed_dir) V=1 MLNX_CFLAGS="" kernel; \
	    $(MAKE) --directory=$(mlnx_ofed_dir) DEPMOD=true install_kernel; \
	    while read -r line; do \
	      module="$$(basename $${line})"; \
	      $(FIND) /lib/modules/$(kernel_ver)$$i/kernel/drivers \
	      -name $${module} -type f -delete; \
	    done <<< "$$($(FIND) \
	    /lib/modules/$(kernel_ver)$$i/extra/mlnx-ofa_kernel -name *.ko)"; \
	    $(FIND) /lib/modules/$(kernel_ver)$$i/kernel/drivers \
	    -empty -type d -delete; \
	    $(MKDIR) $(chroot_build)/initramfs/lib/modules/$(kernel_ver)$$i; \
	    cd /lib/modules/$(kernel_ver)$$i/extra/mlnx-ofa_kernel && \
	    $(INSTALL) -m 0644 compat/mlx_compat.ko \
	    $(chroot_build)/initramfs/lib/modules/$(kernel_ver)$$i/ && \
	    $(INSTALL) -m 0644 drivers/nvme/host/nvme.ko \
	    $(chroot_build)/initramfs/lib/modules/$(kernel_ver)$$i/ && \
	    $(INSTALL) -m 0644 drivers/nvme/host/nvme-core.ko \
	    $(chroot_build)/initramfs/lib/modules/$(kernel_ver)$$i/ && cd -; \
	  else \
	    $(MKDIR) $(chroot_build)/initramfs/lib/modules/$(kernel_ver)$$i; \
	    cd /lib/modules/$(kernel_ver)$$i/kernel && \
	    $(INSTALL) -m 0644 drivers/nvme/host/nvme.ko \
	    $(chroot_build)/initramfs/lib/modules/$(kernel_ver)$$i/ && \
	    $(INSTALL) -m 0644 drivers/nvme/host/nvme-core.ko \
	    $(chroot_build)/initramfs/lib/modules/$(kernel_ver)$$i/ && cd -; \
	  fi; \
	  $(ECHO) "### Compiling the SCST core and target drivers..."; \
	  $(SED) -i -e '/CONFIG_SCST_FORWARD_MODE_PASS_THROUGH/s/^\/\* //' \
	  -e '/CONFIG_SCST_FORWARD_MODE_PASS_THROUGH/s/ \*\/$$//' \
	  $(scst_src)/scst/include/scst.h; \
	  $(MAKE) --directory=$(scst_src) KDIR=$(linux_src) \
	  KVER=$(kernel_ver)$$i scst; \
	  $(MAKE) --directory=$(scst_src) KDIR=$(linux_src) \
	  KVER=$(kernel_ver)$$i \
	  INSTALL_DIR_H=/usr/include/scst scst_install; \
	  BUILD_2X_MODULE=y CONFIG_SCSI_QLA_FC=y CONFIG_SCSI_QLA2XXX_TARGET=y \
	  $(MAKE) --directory=$(scst_src) QLA_INI_DIR=$(qla_ini_dir) \
	  QLA_DIR=$(qla_dir) KDIR=$(linux_src) KVER=$(kernel_ver)$$i \
	  qla; \
	  BUILD_2X_MODULE=y CONFIG_SCSI_QLA_FC=y CONFIG_SCSI_QLA2XXX_TARGET=y \
	  $(MAKE) --directory=$(scst_src) QLA_INI_DIR=$(qla_ini_dir) \
	  QLA_DIR=$(qla_dir) KDIR=$(linux_src) KVER=$(kernel_ver)$$i \
	  qla_install; \
	  $(MAKE) --directory=$(scst_src)/iscsi-scst \
	  include/iscsi_scst_itf_ver.h; \
	  if [ "$(with_mlnx_ofed)" = "yes" ]; then \
	    $(MAKE) --directory=$(scst_src)/iscsi-scst KDIR=$(linux_src) \
	    KVER=$(kernel_ver)$$i INFINIBAND_ENABLED=true OFED_FLAVOR=MOFED \
	    OFED_CFLAGS="-I$(mlnx_ofed_dir)/include \
	    -I$(mlnx_ofed_dir)/include/uapi \
	    -DMOFED_MAJOR=5 -DMOFED_MINOR=0" \
	    ISER_SYMVERS="$(mlnx_ofed_dir)/Module.symvers \
	    $(scst_src)/iscsi-scst/kernel/Module.symvers" V=1 mods; \
	  else \
	    $(MAKE) --directory=$(scst_src)/iscsi-scst KDIR=$(linux_src) \
	    KVER=$(kernel_ver)$$i INFINIBAND_ENABLED=true mods; \
	  fi; \
	  $(MAKE) --directory=$(linux_src) KVER=$(kernel_ver)$$i \
	  SCST_INC_DIR=$(scst_src)/scst/include \
	  M=$(scst_src)/iscsi-scst/kernel modules_install; \
	  $(MAKE) --directory=$(linux_src) KVER=$(kernel_ver)$$i \
	  SCST_INC_DIR=$(scst_src)/scst/include \
	  M=$(scst_src)/iscsi-scst/kernel/isert-scst modules_install; \
	  if [ "$(with_mlnx_ofed)" = "yes" ]; then \
	    $(MAKE) --directory=$(scst_src)/srpt KDIR=$(linux_src) \
	    KVER=$(kernel_ver)$$i OFED_FLAVOR=MOFED \
	    OFED_CFLAGS="-I$(mlnx_ofed_dir)/include \
	    -I$(mlnx_ofed_dir)/include/uapi \
	    -DMOFED_MAJOR=5 -DMOFED_MINOR=0" \
	    OFED_MODULE_SYMVERS="$(mlnx_ofed_dir)/Module.symvers" V=1 all; \
	  else \
	    $(MAKE) --directory=$(scst_src)/srpt KDIR=$(linux_src) \
	    KVER=$(kernel_ver)$$i all; \
	  fi; \
	  $(MAKE) --directory=$(linux_src) KVER=$(kernel_ver)$$i \
	  SCST_INC_DIR=$(scst_src)/scst/include \
	  M=$(scst_src)/srpt/src modules_install; \
	  $(MAKE) --directory=$(scst_src) KDIR=$(linux_src) \
	  KVER=$(kernel_ver)$$i fcst; \
	  $(MAKE) --directory=$(scst_src) KDIR=$(linux_src) \
	  KVER=$(kernel_ver)$$i fcst_install; \
	  if [ "$(enable_mhvtl)" = "yes" ]; then \
	    $(ECHO) "### Compiling the mhVTL module..."; \
	    $(MAKE) --directory=$(mhvtl_src)/kernel KDIR=$(linux_src) \
	    KVER=$(kernel_ver)$$i; \
	    $(MKDIR) /lib/modules/$(kernel_ver)$$i/kernel/drivers/scsi; \
	    $(INSTALL) -m 0644 $(mhvtl_src)/kernel/mhvtl.ko \
	    /lib/modules/$(kernel_ver)$$i/kernel/drivers/scsi/; \
	  fi; \
	  if [ "$(enable_eio)" = "yes" ]; then \
	    $(ECHO) "### Compiling the EnhanceIO driver..."; \
	    $(MAKE) --directory=$(eio_src)/Driver/enhanceio \
	    RHEL5_VER="" KERNEL_SOURCE_VERSION=$(kernel_ver)$$i \
	    KERNEL_TREE=$(linux_src) PWD=$(eio_src)/Driver/enhanceio; \
	    $(MKDIR) /lib/modules/$(kernel_ver)$$i/extra/enhanceio; \
	    $(INSTALL) -m 0644 $(eio_src)/Driver/enhanceio/*.ko \
	    /lib/modules/$(kernel_ver)$$i/extra/enhanceio/; \
	  fi; \
	  if [ "$(enable_btier)" = "yes" ]; then \
	    $(ECHO) "### Compiling the BTIER module..."; \
	    if [ ! -d $(btier_src)/$(notdir $(btier_src)).patch ]; then \
	      $(PATCH) -d $(btier_src) -b \
	      -B $(btier_src)/$(notdir $(btier_src)).patch/ -p1 < \
	      $(chroot_build)/misc/$(notdir $(btier_src)).patch; \
	    fi; \
	    $(MAKE) --directory=$(linux_src) KVER=$(kernel_ver)$$i \
	    M=$(btier_src)/kernel/btier modules; \
	    $(INSTALL) -D -m 0644 $(btier_src)/kernel/btier/btier.ko \
	    /lib/modules/$(kernel_ver)$$i/kernel/drivers/block/btier.ko; \
	  fi; \
	  if [ "$(with_celerity_16_32)" = "yes" ]; then \
	    $(ECHO) "### Compiling the ATTO Celerity 16/32 HBA module..."; \
	    $(MAKE) --directory=$(celerity_16_32_dir)/src KDIR=$(linux_src) \
	    DRIVER_NAME=celerity16fc PWD=$(celerity_16_32_dir)/src install; \
	  fi; \
	  if [ "$(with_atto_scst)" = "yes" ]; then \
	    $(ECHO) "### Compiling the ATTO SCST Target module..."; \
	    $(CAT) $(celerity_16_32_dir)/src/Module.symvers \
	    /usr/include/scst/Module.symvers > \
	    $(atto_scst_dir)/Module.symvers; \
	    $(MAKE) --directory=$(atto_scst_dir) KDIR=$(linux_src) \
	    FULL_KERNEL_VERSION=$(kernel_ver)$$i PWD=$(atto_scst_dir) \
	    MODULE_ROOT=/lib/modules/$(kernel_ver)$$i/extra module; \
	    $(MAKE) --directory=$(linux_src) M="$(atto_scst_dir)" \
	    KVER=$(kernel_ver)$$i modules_install; \
	  fi; \
	  if [ "$(with_ocs_sdk)" = "yes" ]; then \
	    $(ECHO) "### Compiling the Emulex OCS SCST module..."; \
	    $(CP) /usr/include/scst/Module.symvers \
	    $(ocs_sdk_dir)/driver/linux/ocs_fc_scst/; \
	    $(MAKE) --directory=$(linux_src) KVER=$(kernel_ver)$$i \
	    M=$(ocs_sdk_dir)/driver/linux/ocs_fc_scst \
	    SCST_PREFERRED=$(scst_src)/scst/include modules; \
	    $(INSTALL) -D -m 0644 \
	    $(ocs_sdk_dir)/driver/linux/ocs_fc_scst/ocs_fc_scst.ko \
	    /lib/modules/$(kernel_ver)$$i/extra/ocs_fc_scst.ko; \
	  fi; \
	  if [ "$(with_uwire)" = "yes" ]; then \
	    $(ECHO) "### Compiling the Chelsio Uwire SCST module..."; \
	    if [ ! -d $(uwire_dir)/cxgb4_pofcoe.patch ]; then \
	      $(PATCH) -F 3 -d $(uwire_dir)/src/network/cxgb4 -b \
	      -B $(uwire_dir)/cxgb4_pofcoe.patch/ -p1 < \
	      $(uwire_dir)/src/chfcoe/patch/cxgb4_pofcoe.patch; \
	    fi; \
	    $(SED) -i 's/CXGB_FCOE_DBG(adapter/CXGB_FCOE_DBG(adap/g' \
	    $(uwire_dir)/src/network/cxgb4/cxgb4_fcoe.c; \
	    $(SED) -i 's/inline unsigned int/unsigned int/g' \
	    $(uwire_dir)/src/network/cxgb4/l2t.h; \
	    $(MAKE) --directory=$(uwire_dir)/src/network \
	    KERNELRELEASE=$(kernel_ver)$$i DEBUG=1 KDIR=$(linux_src) \
	    disable_bonding=1 po_fcoe=1 toe; \
	    $(SED) -i 's/ln -sf $$(fixup_fwdir)\//ln -sf /g' \
	    $(uwire_dir)/src/network/firmware/Makefile; \
	    $(SED) -i 's/updates\/drivers/kernel\/drivers/' \
	    $(uwire_dir)/src/network/csiostor/Makefile; \
	    $(SED) -i 's/updates\/drivers/kernel\/drivers/' \
	    $(uwire_dir)/src/network/cxgb4/Makefile; \
	    $(SED) -i 's/updates\/drivers/kernel\/drivers/' \
	    $(uwire_dir)/src/network/cxgb4vf/Makefile; \
	    $(SED) -i 's/updates\/drivers/kernel\/drivers/' \
	    $(uwire_dir)/src/network/iw_cxgb4/Makefile; \
	    $(SED) -i 's/updates\/drivers/kernel\/drivers/' \
	    $(uwire_dir)/src/network/t4_tom/Makefile; \
	    $(SED) -i 's/updates\/drivers/kernel\/drivers/' \
	    $(uwire_dir)/src/network/toecore/Makefile; \
	    $(MAKE) --directory=$(uwire_dir)/src/network \
	    KERNELRELEASE=$(kernel_ver)$$i DEBUG=1 KDIR=$(linux_src) \
	    PREFIX="" fixup_fwdir=/lib/firmware/cxgb4 \
	    disable_bonding=1 po_fcoe=1 utsrelease=$(kernel_ver)$$i install; \
	    $(MAKE) --directory=$(uwire_dir)/src/chfcoe/src \
	    KERNELRELEASE=$(kernel_ver)$$i \
	    CXGB4_SRC_PATH="$(uwire_dir)/src/network/cxgb4" \
	    CSIOSTOR_SRC_PATH="$(uwire_dir)/src/network/csiostor/include" \
	    FIRMWARE_PATH="$(uwire_dir)/src/network/firmware" \
	    KDIR="$(linux_src)" SCST_INC="/usr/include/scst" \
	    target=1; \
	    $(MAKE) --directory=$(linux_src) M="$(uwire_dir)/src/chfcoe/src" \
	    KVER=$(kernel_ver)$$i modules_install; \
	  fi; \
	  if [ "$(with_rapiddisk)" = "yes" ]; then \
	    $(ECHO) "### Compiling the RapidDisk modules..."; \
	    $(MAKE) --directory=$(linux_src) KVER=$(kernel_ver)$$i \
	    M=$(rapiddisk_dir)/rapiddisk-master/module; \
	    $(MAKE) --directory=$(linux_src) \
	    M=$(rapiddisk_dir)/rapiddisk-master/module modules_install; \
	  fi; \
	  if [ "$(enable_zfs)" = "yes" ] && [ "$$i" = "$(prod_suffix)" ]; then \
	    $(ECHO) "### Compiling the ZFS on Linux modules..."; \
	    if [ ! -f "$(zfs_src)/configure" ]; then \
	      cd $(zfs_src) && ./autogen.sh; \
	    fi; \
	    cd $(zfs_src) && ./configure --prefix=/usr --sysconfdir=/etc \
	    --with-linux=$(linux_src) --with-linux-obj=$(linux_src) \
	    --with-udevdir="/usr/lib/udev" --disable-silent-rules; \
	    $(MAKE) --directory=$(zfs_src)/module modules; \
	    $(MAKE) --directory=$(zfs_src)/module modules_install; \
	  fi; \
	  $(ECHO) "### Compiling the Celestica Switchtec NTB driver..."; \
	  $(CP) -f $(switchtec_src)/Driver/Switchtec/switchtec_sg.c \
	  $(cls_switchtec)/; \
	  $(CP) -f $(switchtec_src)/Driver/Switchtec/switchtec_sg.h \
	  $(cls_switchtec)/; \
	  $(CHMOD) +x $(cls_switchtec)/VERSION-GEN; \
	  $(MAKE) --directory=$(cls_switchtec) MODULE_NAME=cls_switchtec \
	  KDIR=$(linux_src) KVER=$(kernel_ver)$$i; \
	  $(MAKE) --directory=$(linux_src) M=$(cls_switchtec) modules_install; \
	done
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

esos_tui.chroot: build_opts = $$($(CAT) $(chroot_build)/build_opts)
esos_tui.chroot: esos_ver = $$($(CAT) $(chroot_build)/esos_ver)
esos_tui.chroot: git_branch = $$($(CAT) $(chroot_build)/git_branch)
esos_tui.chroot: $(wildcard $(chroot_build)/tui/*.c)
esos_tui.chroot: $(wildcard $(chroot_build)/tui/*.h)
esos_tui.chroot: glibc.chroot ncurses.chroot cdk.chroot iniparser.chroot \
	parted.chroot util-linux.chroot curl.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(MAKE) --directory=$(chroot_build)/tui \
	CFLAGS="-DBUILD_OPTS=\"\\\"$(build_opts)\\\"\" \
	-DESOS_VERSION=\"\\\"$(esos_ver)\\\"\" \
	-DPRODUCT_NAME=\"\\\"$(product)\\\"\" \
	-DGIT_BRANCH=\"\\\"$(git_branch)\\\"\" $(tui_cpp_flags)"
	$(INSTALL) -m 755 $(chroot_build)/tui/esos_tui /usr/local/bin
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

scst.chroot: glibc.chroot esos_kernels.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(MAKE) --directory=$(tgt_src_dir)/iscsi-scst \
	SCST_INC_DIR=$(tgt_src_dir)/scst/include progs
	$(INSTALL) -vD -m 755 $(tgt_src_dir)/iscsi-scst/usr/iscsi-scstd \
	/usr/sbin/iscsi-scstd
	$(INSTALL) -vD -m 755 $(tgt_src_dir)/iscsi-scst/usr/iscsi-scst-adm \
	/usr/sbin/iscsi-scst-adm
	$(INSTALL) -vD -m 644 \
	$(tgt_src_dir)/iscsi-scst/doc/manpages/iscsi-scstd.conf.5 \
	/usr/share/man/man5/iscsi-scstd.conf.5
	$(INSTALL) -vD -m 644 \
	$(tgt_src_dir)/iscsi-scst/doc/manpages/iscsi-scstd.8 \
	/usr/share/man/man8/iscsi-scstd.8
	$(INSTALL) -vD -m 644 \
	$(tgt_src_dir)/iscsi-scst/doc/manpages/iscsi-scst-adm.8 \
	/usr/share/man/man8/iscsi-scst-adm.8
	$(MAKE) --directory=$(tgt_src_dir)/usr \
	SCST_INC_DIR=$(tgt_src_dir)/scst/include all
	$(MAKE) --directory=$(tgt_src_dir)/usr PREFIX=/usr install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

gdb.chroot: glibc.chroot ncurses.chroot zlib.chroot readline.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(SED) -i "/for ac_lib/s/ncurses /ncursesw /" \
	$(tgt_src_dir)/gdb/configure
	$(SED) -i "/for ac_lib/s/ncurses;/ncursesw;/" \
	$(tgt_src_dir)/gdb/configure
	cd $(tgt_src_dir) && ./configure --prefix=/usr --without-python \
	--with-curses --with-system-zlib --with-system-readline
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

valgrind.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

strace.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr --disable-mpers
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

zfs.chroot: esos_kernels.chroot eudev.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(MAKE) --directory=$(tgt_src_dir)/lib install
	$(MAKE) --directory=$(tgt_src_dir)/cmd install
	$(MAKE) --directory=$(tgt_src_dir)/man install
	$(MAKE) --directory=$(tgt_src_dir)/udev install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

celerity_16_32.chroot:
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(INSTALL) -m 0755 $(celerity_16_32_dir)/cli/x64/atdevinfo /usr/sbin/
	$(INSTALL) -m 0755 $(celerity_16_32_dir)/cli/x64/atfcinfo /usr/sbin/
	$(INSTALL) -m 0755 $(celerity_16_32_dir)/cli/x64/atfcnvr /usr/sbin/
	$(INSTALL) -m 0755 $(celerity_16_32_dir)/cli/x64/atflash /usr/sbin/
	$(INSTALL) -m 0755 $(celerity_16_32_dir)/cli/x64/atinfo /usr/sbin/
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

atto_scst.chroot:
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

ocs_sdk.chroot: glibc.chroot libxml2.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(MAKE) --directory=$(ocs_sdk_dir)/tools/user/elxsdkutil \
	LIBXML2_INC="-I/usr/include/libxml2" \
	LIBXML2_LIB="-lxml2 -lm -ldl"
	$(INSTALL) -m 0755 $(ocs_sdk_dir)/tools/user/elxsdkutil/elxsdkutil \
	/usr/sbin/
	$(INSTALL) -m 0755 $(ocs_sdk_dir)/tools/bin/ocs_config.py \
	/usr/sbin/
	$(INSTALL) -m 0755 $(ocs_sdk_dir)/tools/bin/ocs_cpu_info.py \
	/usr/sbin/
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

uwire.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(INSTALL) -m 0755 $(uwire_dir)/src/chfcoe/tools/chfcoe_perftune.sh \
	/usr/sbin/
	$(INSTALL) -m 0755 $(uwire_dir)/src/chfcoe/tools/chinfotool64 \
	/usr/sbin/
	$(MAKE) --directory=$(uwire_dir)/tools/cxgbtool
	$(INSTALL) -m 0755 $(uwire_dir)/tools/cxgbtool/cxgbtool \
	/usr/sbin/
	$(INSTALL) -m 0444 $(uwire_dir)/tools/cxgbtool/cxgbtool.8 \
	/usr/share/man/man8/
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

mlnx_ofed.chroot: esos_kernels.chroot Python.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(SED) -i 's,etc/udev/rules.d,usr/lib/udev/rules.d,g' \
	$(mlnx_ofed_dir)/makefile
	$(SED) -i '312,318 s/^#*/#/' $(mlnx_ofed_dir)/makefile
	$(SED) -i '323,326 s/^#*/#/' $(mlnx_ofed_dir)/makefile
	$(SED) -i '/param, val/s/line.strip()/line.decode("utf-8").strip()/' \
	$(mlnx_ofed_dir)/ofed_scripts/utils/tc_wrap.py
	$(MAKE) --directory=$(mlnx_ofed_dir) MLNX_PYTHON_EXECUTABLE=python3 \
	V=1 build_py_scripts
	$(MAKE) --directory=$(mlnx_ofed_dir) MLNX_PYTHON_EXECUTABLE=python3 \
	V=1 install_scripts
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

rapiddisk.chroot: glibc.chroot jansson.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(MAKE) --directory=$(rapiddisk_dir)/rapiddisk-master/src
	$(INSTALL) -m 0755 $(rapiddisk_dir)/rapiddisk-master/src/rapiddisk \
	/usr/sbin/
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

jansson.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

Linux-PAM.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr --sysconfdir=/etc \
	--libdir=/usr/lib --disable-regenerate-docu --enable-static \
	--enable-db=no --enable-securedir=/lib/security
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(CHMOD) -v 4755 /sbin/unix_chkpwd
	for file in pam pam_misc pamc; do \
	  $(MV) -v /usr/lib/lib$${file}.so.* /lib && \
	  $(LN) -v ../../lib/$$($(READLINK) /usr/lib/lib$${file}.so) \
	  /usr/lib/lib$${file}.so; \
	done
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

busybox.chroot: glibc.chroot Linux-PAM.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(SED) -i 's/bb_basename(p->exe)/p->exe/' \
	$(tgt_src_dir)/libbb/find_pid_by_name.c
	$(MAKE) --directory=$(tgt_src_dir) clean
	$(MAKE) --directory=$(tgt_src_dir) distclean
	$(SED) -e 's/.*CONFIG_STATIC.*/CONFIG_STATIC=y/' \
	$(chroot_build)/misc/$(notdir $(tgt_src_dir)).config > \
	$(tgt_src_dir)/.config
	$(MAKE) --directory=$(tgt_src_dir) CONFIG_EXTRA_LDLIBS="dl"
	$(INSTALL) -D $(tgt_src_dir)/busybox_unstripped \
	$(chroot_build)/initramfs/bin/busybox
	$(MAKE) --directory=$(tgt_src_dir) clean
	$(MAKE) --directory=$(tgt_src_dir) distclean
	$(CP) $(chroot_build)/misc/$(notdir $(tgt_src_dir)).config \
	$(tgt_src_dir)/.config
	$(MAKE) --directory=$(tgt_src_dir)
	$(INSTALL) $(tgt_src_dir)/busybox_unstripped /bin/busybox
	$(INSTALL) -d /usr/share/udhcpc
	$(INSTALL) $(tgt_src_dir)/examples/udhcp/simple.script \
	/usr/share/udhcpc/default.script
	$(ECHO) -e "#! /bin/sh\n\n/bin/busybox awk \"\044\0100\"\n" > \
	/usr/bin/gawk
	$(CHMOD) +x /usr/bin/gawk
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

makedumpfile.chroot: glibc.chroot elfutils.chroot bzip2.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(MAKE) --directory=$(tgt_src_dir)
	$(INSTALL) -D -m 0755 $(tgt_src_dir)/makedumpfile \
	$(chroot_build)/initramfs/usr/sbin/makedumpfile
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

elfutils.chroot: glibc.chroot zlib.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

sysvinit.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(call apply_pkg_patch)
	$(MAKE) --directory=$(tgt_src_dir)/src SULOGINLIBS=-lcrypt \
	CFLAGS="-O2 -fomit-frame-pointer"
	$(MAKE) --directory=$(tgt_src_dir)/src ROOT=/ install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

grub.chroot: glibc.chroot lvm2.chroot freetype.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(call apply_pkg_patch)
	cd $(tgt_src_dir) && ./configure --prefix=/usr --enable-grub-mkfont \
	--enable-device-mapper --disable-efiemu --with-platform=pc \
	--target=i386 --disable-werror
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir)/grub-core install-platformDATA
	$(MAKE) --directory=$(tgt_src_dir) clean
	$(MAKE) --directory=$(tgt_src_dir) distclean
	cd $(tgt_src_dir) && ./configure --prefix=/usr --enable-grub-mkfont \
	--enable-device-mapper --disable-efiemu --with-platform=efi \
	--target=x86_64 --disable-werror
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir)/grub-core install-platformDATA
	$(MAKE) --directory=$(tgt_src_dir) install-exec
	$(ECHO) -e "#! /bin/sh\n\n$(CHROOT_DIR)/lib/ld-linux-x86-64.so.2 \
	--library-path \"$(CHROOT_DIR)/lib:$(CHROOT_DIR)/usr/lib\" \
	$(CHROOT_DIR)/usr/sbin/grub-install \"\044\0100\"\n" > \
	$(chroot_build)/grub-install
	$(CHMOD) +x $(chroot_build)/grub-install
	$(SED) 's/^prefix=.*/prefix=$(subst /,\/,$(CHROOT_DIR)/usr)/' \
	$(tgt_src_dir)/grub-mkconfig_lib > $(chroot_build)/grub-mkconfig_lib
	$(ECHO) -e "#! /bin/sh\n\n$(CHROOT_DIR)/lib/ld-linux-x86-64.so.2 \
	--library-path \"$(CHROOT_DIR)/lib:$(CHROOT_DIR)/usr/lib\" \
	$(CHROOT_DIR)/usr/sbin/grub-bios-setup \"\044\0100\"\n" > \
	$(chroot_build)/grub-bios-setup
	$(CHMOD) +x $(chroot_build)/grub-bios-setup
	$(ECHO) -e "#! /bin/sh\n\n$(CHROOT_DIR)/lib/ld-linux-x86-64.so.2 \
	--library-path \"$(CHROOT_DIR)/lib:$(CHROOT_DIR)/usr/lib\" \
	$(CHROOT_DIR)/usr/bin/grub-mkimage \"\044\0100\"\n" > \
	$(chroot_build)/grub-mkimage
	$(CHMOD) +x $(chroot_build)/grub-mkimage
	$(ECHO) -e "#! /bin/sh\n\n$(CHROOT_DIR)/lib/ld-linux-x86-64.so.2 \
	--library-path \"$(CHROOT_DIR)/lib:$(CHROOT_DIR)/usr/lib\" \
	$(CHROOT_DIR)/usr/bin/grub-mkrelpath \"\044\0100\"\n" > \
	$(chroot_build)/grub-mkrelpath
	$(CHMOD) +x $(chroot_build)/grub-mkrelpath
	$(ECHO) -e "#! /bin/sh\n\n$(CHROOT_DIR)/lib/ld-linux-x86-64.so.2 \
	--library-path \"$(CHROOT_DIR)/lib:$(CHROOT_DIR)/usr/lib\" \
	$(CHROOT_DIR)/usr/sbin/grub-probe \"\044\0100\"\n" > \
	$(chroot_build)/grub-probe
	$(CHMOD) +x $(chroot_build)/grub-probe
	$(MAKE) --directory=$(tgt_src_dir) clean
	$(MAKE) --directory=$(tgt_src_dir) distclean
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

perl.chroot: glibc.chroot db.chroot sqlite-autoconf.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure.gnu --prefix=/usr --verbose
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install.perl INSTALLFLAGS="-f -o"
	$(ECHO) yes | cpan install JROGERS/Net-Telnet-3.04.tar.gz
	$(ECHO) yes | cpan install TIMB/DBI-1.642.tar.gz
	$(ECHO) yes | cpan install ISHIGAKI/DBD-SQLite-1.64.tar.gz
	$(RM) /root/.cpan
	$(RM) /.cpan
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

Python.chroot: glibc.chroot gcc.chroot bzip2.chroot readline.chroot \
	openssl.chroot zlib.chroot sqlite-autoconf.chroot ncurses.chroot \
	db.chroot libxml2.chroot libxslt.chroot curl.chroot util-linux.chroot \
	$(if $(findstring yes,$(enable_python_sql)),\
	postgresql.chroot mysql.chroot,)
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr --enable-shared \
	--with-ensurepip=upgrade
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	pip3 install --upgrade pip
	pip3 install configshell-fb==1.1.23
	pip3 install docutils==0.16
	pip3 install pbr==1.10.0
	pip3 install lockfile==0.12.2
	pip3 install python-daemon==2.1.1
	pip3 install lxml==3.6.4
	pip3 install suds-py3==1.3.3.0
	pip3 install ptyprocess==0.5.1
	pip3 install pexpect==4.2.1
	PYCURL_SSL_LIBRARY=openssl pip3 install pycurl==7.43.0
	pip3 install pyparsing==2.1.10
	pip3 install requests==2.11.1
	pip3 install six==1.10.0
	pip3 install parallax==1.0.4
	pip3 install py-dateutil==2.2
	pip3 install PyYAML==3.13
	pip3 install pytz==2018.5
	pip3 install python-pam==1.8.4
	LDFLAGS=-fno-lto pip3 install uWSGI==2.0.17.1
	pip3 install pySMART.smartx==0.3.9
	pip3 install mdstat==1.0.4
	pip3 install py-dmidecode==0.1.0
	pip3 install netifaces==0.10.9
	pip3 install ordered-set==3.1
	pip3 install deepdiff==4.0.6
	pip3 install pyasn1==0.4.5
	pip3 install pycparser==2.19
	pip3 install cffi==1.11.5
	pip3 install bcrypt==3.1.6
	pip3 install PyNaCl==1.3.0
	pip3 install asn1crypto==0.24.0
	pip3 install cryptography==2.7
	pip3 install paramiko==2.6.0
	pip3 install tzlocal==1.5.1
	pip3 install tzdata==1.2016.8
	pip3 install pyudev==0.22.0
	pip3 install rst2html==2020.7.4
	pip3 install genshi==0.7.5
	pip3 install pygments==2.7.3
	pip3 install rst2html5==1.10.6
	$(QUIET) if [ "$(enable_python_sql)" = "yes" ]; then \
	  pip3 install psycopg2==2.6.2; \
	  pip3 install mysqlclient==1.3.12; \
	  pip3 install SQLAlchemy==1.1.1; \
	fi
	$(RM) /.cache
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

qlogic_fw.chroot:
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(CP) $(tgt_src_dir)/*.bin /lib/firmware/
	$(CP) $(tgt_src_dir)/LICENSE /lib/firmware/QLOGIC_FW_LICENSE
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

scstadmin.chroot: perl_mod = $(wildcard $(scst_src)/scstadmin/scstadmin/scst-*)
scstadmin.chroot: perl_lib = $(wildcard /usr/lib/perl5/5.*)
scstadmin.chroot: perl.chroot scst.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(perl_mod) && PERL5LIB="$(perl_lib)" /usr/bin/perl \
	Makefile.PL PREFIX=/usr PERL_LIB="$(perl_lib)" \
	PERL_ARCHLIB="$(perl_lib)/x86_64-linux"
	$(MAKE) --directory=$(perl_mod) PERL5LIB="$(perl_lib)"
	$(MAKE) --directory=$(perl_mod) PERL5LIB="$(perl_lib)" install
	$(INSTALL) -m 755 $(scst_src)/scstadmin/scstadmin/scstadmin /usr/sbin/
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

openssh.chroot: glibc.chroot zlib.chroot openssl.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix="" --exec-prefix=/usr \
	--sysconfdir=/etc/ssh --datarootdir=/usr/share \
	--without-openssl-header-check
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) DESTDIR=/ install
	$(INSTALL) -m 0755 $(tgt_src_dir)/contrib/ssh-copy-id \
	/usr/bin/ssh-copy-id
	$(SED) -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' \
	/etc/ssh/sshd_config
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

vixie-cron.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(MAKE) --directory=$(tgt_src_dir) all
	$(INSTALL) -m 111 $(tgt_src_dir)/cron /usr/sbin/
	$(INSTALL) -m 4111 $(tgt_src_dir)/crontab /usr/bin/
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

openssl.chroot: glibc.chroot gcc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(call apply_pkg_patch)
	cd $(tgt_src_dir) && ./config shared zlib-dynamic \
	--prefix=/usr --openssldir=/etc/ssl
	$(MAKE) --jobs=1 --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install_sw install_ssldirs
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

zlib.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

ncurses.chroot: glibc.chroot gcc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(call apply_pkg_patch)
	cd $(tgt_src_dir) && ./configure --prefix=/usr --with-shared \
	--without-gpm --mandir=/usr/share/man --enable-widec
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(MKDIR) /usr/include/ncursesw
	$(LN) ../ncurses.h /usr/include/ncursesw/ncurses.h
	$(LN) ../term.h /usr/include/ncursesw/term.h
	$(LN) -v libncursesw.so /usr/lib/libncurses.so
	$(LN) -v libformw.so /usr/lib/libform.so
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

e2fsprogs.chroot: glibc.chroot util-linux.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(RM) $(chroot_build)/e2fsprogs-build
	$(MKDIR) $(chroot_build)/e2fsprogs-build
	cd $(chroot_build)/e2fsprogs-build && LIBS="-lpthread" \
	$(tgt_src_dir)/configure --prefix=/usr --enable-elf-shlibs \
	--sysconfdir=/etc --enable-verbose-makecmds --disable-libuuid \
	--disable-libblkid --disable-uuidd --enable-symlink-install \
	--enable-symlink-build
	$(MAKE) --directory=$(chroot_build)/e2fsprogs-build \
	LIBUUID="-luuid" LIBBLKID="-lblkid"
	$(MAKE) --directory=$(chroot_build)/e2fsprogs-build install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

ssmtp.chroot: glibc.chroot openssl.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && CFLAGS="-lcrypto" \
	./configure --enable-ssl --prefix="" --exec-prefix=/usr
	$(MAKE) --directory=$(tgt_src_dir)
	$(INSTALL) -m 755 $(tgt_src_dir)/ssmtp /usr/sbin/
	$(LN) ssmtp /usr/sbin/sendmail
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

libibumad.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr --sysconfdir=/etc \
	--localstatedir=/var
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

libibverbs.chroot: glibc.chroot libnl.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr --sysconfdir=/etc \
	--localstatedir=/var
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

libcxgb3.chroot: glibc.chroot libibverbs.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr --sysconfdir=/etc
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

libcxgb4.chroot: glibc.chroot libibverbs.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr --sysconfdir=/etc
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

libi40iw.chroot: glibc.chroot libibverbs.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr --sysconfdir=/etc
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

libmlx4.chroot: glibc.chroot libibverbs.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr --sysconfdir=/etc
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

libmlx5.chroot: glibc.chroot libibverbs.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && CFLAGS='-Wstringop-truncation' \
	./configure --prefix=/usr --sysconfdir=/etc
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

libmthca.chroot: glibc.chroot libibverbs.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr --sysconfdir=/etc
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

libnes.chroot: glibc.chroot libibverbs.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr --sysconfdir=/etc
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

libocrdma.chroot: glibc.chroot libibverbs.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr --sysconfdir=/etc
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

srptools.chroot: glibc.chroot libibumad.chroot libibverbs.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ac_cv_func_malloc_0_nonnull=yes ./configure \
	--prefix=/usr --sysconfdir=/etc --localstatedir=/var
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install-sbinPROGRAMS
	$(MAKE) --directory=$(tgt_src_dir) install-sbinSCRIPTS
	$(MAKE) --directory=$(tgt_src_dir) install-man
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

lsscsi.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr --disable-nvme-supp
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

sg3_utils.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(INSTALL) -m 0755 $(tgt_src_dir)/scripts/rescan-scsi-bus.sh \
	/usr/sbin/rescan-scsi-bus.sh
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

groff.chroot: glibc.chroot gcc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr
	$(MAKE) --directory=$(tgt_src_dir) CCC="g++ -std=c++98 \
	-I$(wildcard /tools/include/c++/*) \
	-I$(wildcard /tools/include/c++/*/x86_64-pc-linux-gnu)"
	$(MAKE) --directory=$(tgt_src_dir) install
	$(LN) tbl /usr/bin/gtbl
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

kexec-tools.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && LDFLAGS="--static" \
	CFLAGS="-DEM_486=6 -DEM_386=3" ./configure --prefix=/usr
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

iniparser.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(MAKE) --directory=$(tgt_src_dir) CFLAGS="-O2 -fPIC -Wall"
	$(INSTALL) -m 0755 $(tgt_src_dir)/libiniparser.so.* /usr/lib/
	$(INSTALL) -m 0644 $(tgt_src_dir)/src/iniparser.h /usr/include/
	$(INSTALL) -m 0644 $(tgt_src_dir)/src/dictionary.h /usr/include/
	$(LN) -v libiniparser.so.1 /usr/lib/libiniparser.so
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

cdk.chroot: glibc.chroot ncurses.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(call apply_pkg_patch)
	cd $(tgt_src_dir) && ./configure --prefix=/usr --with-ncursesw \
	--with-libtool --mandir=/usr/share/man --with-shared
	$(MAKE) --directory=$(tgt_src_dir) LIBS="-lncursesw"
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

lvm2.chroot: glibc.chroot corosync.chroot dlm.chroot \
	thin-provisioning-tools.chroot eudev.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ac_cv_path_MODPROBE_CMD="/sbin/modprobe" \
	./configure --with-lvm1=none --disable-selinux --prefix=/usr \
	--with-clvmd=corosync --with-cluster=internal --enable-ocf \
	--enable-cmirrord --disable-readline --with-thin=internal \
	--with-thin-check=/usr/sbin/thin_check --with-cache=internal \
	--enable-udev_sync --enable-udev_rules --enable-lvmetad \
	--disable-udev-systemd-background-jobs --enable-lockd-dlm \
	--enable-pkgconfig
	$(SED) -i "/VGOUT=/s/OCF_ERR_GENERIC/OCF_NOT_RUNNING/" \
	$(tgt_src_dir)/scripts/VolumeGroup.ocf
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir)/man install
	$(MAKE) --directory=$(tgt_src_dir)/tools install
	$(MAKE) --directory=$(tgt_src_dir)/libdm install
	$(MAKE) --directory=$(tgt_src_dir)/lib install
	$(MAKE) --directory=$(tgt_src_dir)/scripts install
	$(MAKE) --directory=$(tgt_src_dir)/daemons install
	$(MAKE) --directory=$(tgt_src_dir)/udev install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

xfsprogs.chroot: glibc.chroot util-linux.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && CFLAGS="-DNO_ENDIAN_DEP_TYPES" \
	./configure --prefix=/usr
	$(MAKE) --directory=$(tgt_src_dir) BUILD_VERBOSE=1
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

drbd-utils.chroot: glibc.chroot eudev.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(call apply_pkg_patch)
	$(SED) -e '/install -d $$(DESTDIR)$$(INITDIR)/ s/^#*/#/' -i \
	$(tgt_src_dir)/scripts/Makefile.in
	$(SED) -e '/install -m 755 drbd $$(DESTDIR)$$(INITDIR)\// s/^#*/#/' -i \
	$(tgt_src_dir)/scripts/Makefile.in
	cd $(tgt_src_dir) && ./configure --prefix=/usr --without-83support \
	--with-udev --without-xen --with-pacemaker --without-heartbeat \
	--without-rgmanager --without-bashcompletion --with-distro=generic \
	--sysconfdir=/etc --localstatedir=/var --with-initscripttype=sysv \
	--with-prebuiltman
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

mdadm.chroot: glibc.chroot corosync.chroot dlm.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(call apply_pkg_patch)
	$(MAKE) --directory=$(tgt_src_dir) mdadm.static \
	CXFLAGS="-Wno-address-of-packed-member -Wno-absolute-value"
	$(INSTALL) -D -m 755 $(tgt_src_dir)/mdadm.static \
	$(chroot_build)/initramfs/sbin/mdadm
	$(MAKE) --directory=$(tgt_src_dir) clean
	$(MAKE) --directory=$(tgt_src_dir) \
	MAP_DIR="/var/run/mdadm" RUN_DIR="/var/run/mdadm" \
	CXFLAGS="-Wno-address-of-packed-member -Wno-absolute-value"
	$(INSTALL) -D -m 755 $(tgt_src_dir)/mdadm /sbin/mdadm
	$(INSTALL) -D -m 755 $(tgt_src_dir)/mdmon /sbin/mdmon
	$(MAKE) --directory=$(tgt_src_dir) install-man
	$(MAKE) --directory=$(tgt_src_dir) UDEVDIR=/usr/lib/udev install-udev
	$(MAKE) --directory=$(tgt_src_dir) clean
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

parted.chroot: glibc.chroot util-linux.chroot lvm2.chroot readline.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(QUIET) if ! $(GREP) -q '#include <sys/sysmacros.h>' \
	  $(tgt_src_dir)/libparted/arch/linux.c; then \
	  $(SED) -i '/utsname.h/a#include <sys/sysmacros.h>' \
	  $(tgt_src_dir)/libparted/arch/linux.c; \
	fi
	cd $(tgt_src_dir) && ./configure --prefix=/usr --disable-static
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

opensm.chroot: glibc.chroot gcc.chroot libibumad.chroot libibverbs.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr --sysconfdir=/etc \
	--localstatedir=/var
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install-data
	$(MAKE) --directory=$(tgt_src_dir)/opensm install-exec
	$(MAKE) --directory=$(tgt_src_dir)/osmtest install-exec
	$(MAKE) --directory=$(tgt_src_dir)/complib install
	$(MAKE) --directory=$(tgt_src_dir)/libvendor install
	$(MAKE) --directory=$(tgt_src_dir)/include install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

libqb.chroot: glibc.chroot glib.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(LN) -v libqb.so.0.19.2 /usr/lib/libqb.so
	$(RM) /usr/lib/libqb.la
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

pacemaker.chroot: glibc.chroot libqb.chroot util-linux.chroot glib.chroot \
	libxml2.chroot ncurses.chroot bzip2.chroot corosync.chroot \
	libxslt.chroot glue.chroot Python.chroot libtool.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(QUIET) if [ ! -f "$(tgt_src_dir)/configure" ]; then \
	  $(SED) -i "/AC_CHECK_LIB/s/ncurses/ncursesw/g" \
	  $(tgt_src_dir)/configure.ac; \
	  $(SED) -i 's/-lncurses/-lncursesw/g' \
	  $(tgt_src_dir)/configure.ac; \
	  $(SED) -i 's/--libs ncurses/--libs ncursesw/g' \
	  $(tgt_src_dir)/configure.ac; \
	  cd $(tgt_src_dir) && ./autogen.sh; \
	fi
	cd $(tgt_src_dir) && ./configure --prefix=/usr --disable-upstart \
	--disable-systemd --without-heartbeat --without-snmp --without-esmtp \
	--disable-fatal-warnings --disable-ansi --disable-silent-rules \
	--sysconfdir=/etc --localstatedir=/var --with-python
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir)/replace install
	$(MAKE) --directory=$(tgt_src_dir)/include install
	$(MAKE) --directory=$(tgt_src_dir)/lib install
	$(MAKE) --directory=$(tgt_src_dir)/mcp install-exec
	$(MAKE) --directory=$(tgt_src_dir)/pengine install
	$(MAKE) --directory=$(tgt_src_dir)/cib install
	$(MAKE) --directory=$(tgt_src_dir)/crmd install
	$(MAKE) --directory=$(tgt_src_dir)/fencing install
	$(MAKE) --directory=$(tgt_src_dir)/lrmd init_SCRIPTS="" install
	$(MAKE) --directory=$(tgt_src_dir)/attrd install
	$(MAKE) --directory=$(tgt_src_dir)/tools install
	$(MAKE) --directory=$(tgt_src_dir)/xml install
	$(MAKE) --directory=$(tgt_src_dir)/cts install
	$(MAKE) --directory=$(tgt_src_dir)/doc install
	$(MAKE) --directory=$(tgt_src_dir)/extra install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

corosync.chroot: glibc.chroot libqb.chroot nss.chroot librdmacm.chroot \
	libibverbs.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && \
	rdmacm_CFLAGS="-I/usr/include/rdma" rdmacm_LIBS="-lrdmacm" \
	ibverbs_CFLAGS="-I/usr/include/infiniband" ibverbs_LIBS="-libverbs" \
	./configure --prefix=/usr --sysconfdir=/etc \
	--localstatedir=/var --enable-xmlconf --enable-rdma
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir)/include install
	$(MAKE) --directory=$(tgt_src_dir)/common_lib install
	$(MAKE) --directory=$(tgt_src_dir)/lib install
	$(MAKE) --directory=$(tgt_src_dir)/exec install
	$(MAKE) --directory=$(tgt_src_dir)/tools install
	$(MAKE) --directory=$(tgt_src_dir)/test install
	$(MAKE) --directory=$(tgt_src_dir)/cts install
	$(MAKE) --directory=$(tgt_src_dir)/pkgconfig install
	$(MAKE) --directory=$(tgt_src_dir)/man install
	$(MAKE) --directory=$(tgt_src_dir)/qdevices install
	$(MAKE) --directory=$(tgt_src_dir)/conf install-corosysxmlxsltDATA
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

nss.chroot: glibc.chroot gcc.chroot sqlite-autoconf.chroot zlib.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(call apply_pkg_patch)
	$(SED) -i 's#$$(LIBRARY) ##' $(tgt_src_dir)/nspr/config/rules.mk
	cd $(tgt_src_dir)/nspr && ./configure --prefix=/usr --with-mozilla \
	--with-pthreads --enable-64bit
	$(MAKE) --directory=$(tgt_src_dir)/nspr
	$(MAKE) --directory=$(tgt_src_dir)/nspr install
	$(MAKE) --directory=$(tgt_src_dir)/nss -j1 BUILD_OPT=1 \
	NSPR_INCLUDE_DIR=/usr/include/nspr USE_SYSTEM_ZLIB=1 ZLIB_LIBS=-lz \
	NSS_ENABLE_WERROR=0 USE_64=1 NSS_USE_SYSTEM_SQLITE=1
	$(INSTALL) -v -m755 $(tgt_src_dir)/dist/Linux*/lib/*.so /usr/lib
	$(INSTALL) -v -m644 $(tgt_src_dir)/dist/Linux*/lib/{*.chk,libcrmf.a} \
	/usr/lib
	$(INSTALL) -v -m755 -d /usr/include/nss
	$(CP) -v -RL $(tgt_src_dir)/dist/{public,private}/nss/* \
	/usr/include/nss
	$(CHMOD) 644 /usr/include/nss/*.h
	$(INSTALL) -v -m755 \
	$(tgt_src_dir)/dist/Linux*/bin/{certutil,nss-config,pk12util} /usr/bin
	$(INSTALL) -v -m644 $(tgt_src_dir)/dist/Linux*/lib/pkgconfig/nss.pc \
	/usr/lib/pkgconfig/
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

glib.chroot: glibc.chroot zlib.chroot libffi.chroot util-linux.chroot \
	elfutils.chroot Python.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(RM) $(tgt_src_dir)/build
	$(MKDIR) $(tgt_src_dir)/build
	cd $(tgt_src_dir)/build && \
	meson --prefix=/usr -Dselinux=disabled -Dinternal_pcre=true ..
	cd $(tgt_src_dir)/build && ninja
	cd $(tgt_src_dir)/build && ninja install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

libxml2.chroot: glibc.chroot zlib.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr --without-python \
	--with-threads --without-lzma
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

libxslt.chroot: glibc.chroot libxml2.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr \
	--without-python --without-crypto
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

bzip2.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(SED) -i 's@\(ln -s -f \)$(PREFIX)/bin/@\1@' $(tgt_src_dir)/Makefile
	$(SED) -i "s@(PREFIX)/man@(PREFIX)/share/man@g" $(tgt_src_dir)/Makefile
	$(MAKE) --file=$(tgt_src_dir)/Makefile --directory=$(tgt_src_dir)
	$(INSTALL) -v $(tgt_src_dir)/libbz2.a /usr/lib
	$(MAKE) --directory=$(tgt_src_dir) clean
	$(MAKE) --file=$(tgt_src_dir)/Makefile-libbz2_so \
	--directory=$(tgt_src_dir)
	$(INSTALL) -v $(tgt_src_dir)/libbz2.so.1.0.6 /usr/lib
	$(LN) libbz2.so.1.0.6 /usr/lib/libbz2.so.1.0
	$(LN) libbz2.so.1.0.6 /usr/lib/libbz2.so
	$(INSTALL) -v -m644 $(tgt_src_dir)/bzlib.h /usr/include
	$(MAKE) --directory=$(tgt_src_dir) distclean
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

crmsh.chroot: glibc.chroot Python.chroot glue.chroot pacemaker.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(QUIET) if [ ! -f "$(tgt_src_dir)/configure" ]; then \
	  cd $(tgt_src_dir) && ./autogen.sh; \
	fi
	cd $(tgt_src_dir) && ./configure --prefix=/usr \
	--localstatedir=/var --sysconfdir=/etc
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) DESTDIR=/ install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

libaio.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) prefix=/usr install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

glue.chroot: glibc.chroot libaio.chroot libxml2.chroot bzip2.chroot \
	curl.chroot util-linux.chroot glib.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(QUIET) if [ ! -f "$(tgt_src_dir)/configure" ]; then \
	  cd $(tgt_src_dir) && ./autogen.sh; \
	fi
	cd $(tgt_src_dir) && LIBS="-lz -lm -ldl -lxml2" ./configure \
	--prefix=/usr --disable-ansi --disable-fatal-warnings \
	--sysconfdir=/etc --localstatedir=/var --disable-doc
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir)/include install
	$(MAKE) --directory=$(tgt_src_dir)/replace install
	$(MAKE) --directory=$(tgt_src_dir)/lib install
	$(MAKE) --directory=$(tgt_src_dir)/lrm install
	$(MAKE) --directory=$(tgt_src_dir)/logd install-exec
	$(MAKE) --directory=$(tgt_src_dir)/hb_report install
	$(MAKE) --directory=$(tgt_src_dir)/config install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

readline.chroot: glibc.chroot ncurses.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr --disable-static \
	--with-curses
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

resource-agents.chroot: glib.chroot glue.chroot docbook-xsl-nons.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(call apply_pkg_patch)
	$(QUIET) if [ ! -f "$(tgt_src_dir)/configure" ]; then \
	  cd $(tgt_src_dir) && ./autogen.sh; \
	fi
	cd $(tgt_src_dir) && ./configure --prefix=/usr --disable-ansi \
	--disable-fatal-warnings --sysconfdir=/etc --localstatedir=/var
	$(SED) -i 's/ps -e -o cmd/ps -e -o comm/' \
	$(tgt_src_dir)/heartbeat/iscsi
	$(MAKE) --directory=$(tgt_src_dir)/rgmanager
	$(MAKE) --directory=$(tgt_src_dir)/include
	$(MAKE) --directory=$(tgt_src_dir)/heartbeat
	$(MAKE) --directory=$(tgt_src_dir)/tools
	$(MAKE) --directory=$(tgt_src_dir)/rgmanager install
	$(MAKE) --directory=$(tgt_src_dir)/include install
	$(MAKE) --directory=$(tgt_src_dir)/heartbeat install
	$(MAKE) --directory=$(tgt_src_dir)/tools install
	$(LN) /usr/lib/ocf/lib/heartbeat/ocf-shellfuncs \
	/usr/lib/ocf/resource.d/heartbeat/.ocf-shellfuncs
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

mhvtl.chroot: glibc.chroot lzo.chroot zlib.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(MAKE) --directory=$(tgt_src_dir) MHVTL_HOME_PATH="/mnt/mhvtl"
	$(INSTALL) -m 755 $(tgt_src_dir)/usr/libvtlscsi.so /usr/lib/
	$(INSTALL) -m 755 $(tgt_src_dir)/usr/libvtlcart.so /usr/lib/
	$(INSTALL) -m 755 $(tgt_src_dir)/usr/vtltape /usr/bin/
	$(INSTALL) -m 755 $(tgt_src_dir)/usr/vtllibrary /usr/bin/
	$(INSTALL) -m 755 $(tgt_src_dir)/usr/vtlcmd /usr/bin/
	$(INSTALL) -m 755 $(tgt_src_dir)/usr/mktape /usr/bin/
	$(INSTALL) -m 755 $(tgt_src_dir)/usr/dump_tape /usr/bin/
	$(INSTALL) -m 755 $(tgt_src_dir)/usr/edit_tape /usr/bin/
	$(INSTALL) -m 755 $(tgt_src_dir)/usr/tapeexerciser /usr/bin/
	$(INSTALL) -m 700 $(tgt_src_dir)/usr/build_library_config /usr/bin/
	$(INSTALL) -m 700 $(tgt_src_dir)/usr/make_vtl_media /usr/bin/
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

lzo.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr --enable-shared \
	--disable-static
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

mhash.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

lessfs.chroot: glibc.chroot mhash.chroot openssl.chroot lzo.chroot fuse.chroot \
	db.chroot tokyocabinet.chroot snappy.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(call apply_pkg_patch)
	cd $(tgt_src_dir) && \
	DEPS_LIBS="-ltokyocabinet -lfuse -lbz2 -lssl -lcrypto -lpthread" \
        ./configure --prefix=/usr --with-crypto --with-lzo --with-snappy \
	--without-hamsterdb --with-berkeleydb
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

qemu.chroot: glibc.chroot numactl.chroot libgcrypt.chroot Linux-PAM.chroot \
	eudev.chroot curl.chroot libaio.chroot bzip2.chroot lzo.chroot \
	libusb.chroot libxml2.chroot Python.chroot zlib.chroot pixman.chroot \
	multipath-tools.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(call apply_pkg_patch)
	$(RM) $(tgt_src_dir)/build
	$(MKDIR) $(tgt_src_dir)/build
	cd $(tgt_src_dir)/build && ../configure --prefix=/usr \
	--sysconfdir=/etc --target-list=x86_64-softmmu --cpu=x86_64 \
	--disable-blobs --enable-gcrypt --enable-auth-pam --enable-libudev \
	--enable-mpath --enable-vnc --enable-curl --enable-kvm \
	--enable-linux-aio --enable-attr --enable-vhost-net \
	--enable-vhost-scsi --enable-vhost-kernel --enable-libusb --enable-lzo \
	--enable-bzip2 --enable-numa --enable-libxml2 --enable-tools \
	--disable-user --disable-linux-user --disable-bsd-user --disable-docs \
	--disable-guest-agent --disable-guest-agent-msi --disable-modules \
	--disable-module-upgrades --disable-gnutls --disable-nettle \
	--disable-auth-pam --disable-sdl --disable-sdl-image --disable-gtk \
	--disable-vte --disable-curses --disable-iconv --disable-vnc-sasl \
	--disable-vnc-jpeg --disable-vnc-png --disable-cocoa --disable-virtfs \
	--disable-virtiofsd --disable-xen --disable-xen-pci-passthrough \
	--disable-brlapi --disable-membarrier --disable-fdt --disable-hax \
	--disable-hvf --disable-whpx --disable-rdma --disable-pvrdma \
	--disable-vde --disable-netmap --disable-linux-io-uring \
	--disable-cap-ng --disable-vhost-vsock --disable-vhost-user \
	--disable-vhost-user-blk-server --disable-vhost-vdpa --disable-spice \
	--disable-rbd --disable-libiscsi --disable-libnfs --disable-smartcard \
	--disable-u2f --disable-live-block-migration --disable-usb-redir \
	--disable-snappy --disable-lzfse --disable-zstd --disable-tpm \
	--disable-libssh --disable-replication --disable-opengl \
	--disable-virglrenderer --disable-xfsctl --disable-qom-cast-debug \
	--disable-bochs --disable-cloop --disable-dmg --disable-qcow1 \
	--disable-vdi --disable-vvfat --disable-qed --disable-parallels \
	--disable-crypto-afalg --disable-capstone --disable-libpmem \
	--disable-xkbcommon --disable-libdaxctl
	$(CP) /usr/include/gnu/stubs-64.h /usr/include/gnu/stubs-32.h
	$(MAKE) --directory=$(tgt_src_dir)/build
	$(MAKE) --directory=$(tgt_src_dir)/build install
	$(RM) /usr/include/gnu/stubs-32.h
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

pixman.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

libvirt.chroot: glibc.chroot perl.chroot Python.chroot libxml2.chroot \
	libxslt.chroot nfs-utils.chroot gnutls.chroot yajl.chroot \
	qemu.chroot attr.chroot util-linux.chroot eudev.chroot \
	curl.chroot numactl.chroot openwsman.chroot libpciaccess.chroot \
	readline.chroot multipath-tools.chroot lvm2.chroot ncurses.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(call apply_pkg_patch)
	$(RM) $(tgt_src_dir)/build
	$(MKDIR) $(tgt_src_dir)/build
	cd $(tgt_src_dir) && meson build --prefix=/usr \
	-Dapparmor=disabled -Dattr=enabled -Daudit=disabled \
	-Dbash_completion=disabled -Dblkid=enabled -Dcapng=disabled \
	-Dcurl=enabled -Ddocs=disabled -Ddriver_bhyve=disabled \
	-Ddriver_esx=disabled -Ddriver_hyperv=disabled \
	-Ddriver_interface=enabled -Ddriver_libvirtd=enabled \
	-Ddriver_libxl=disabled -Ddriver_lxc=disabled -Ddriver_network=enabled \
	-Ddriver_openvz=disabled -Ddriver_qemu=enabled -Ddriver_remote=enabled \
	-Ddriver_secrets=enabled -Ddriver_test=enabled -Ddriver_vbox=disabled \
	-Ddriver_vmware=disabled -Ddriver_vz=disabled -Ddtrace=disabled \
	-Dexpensive_tests=disabled -Dfirewalld=disabled \
	-Dfirewalld_zone=disabled -Dfuse=disabled -Dgit_werror=disabled \
	-Dglusterfs=disabled -Dhost_validate=disabled -Dinit_script=none \
	-Dlibiscsi=disabled -Dlibnl=disabled -Dlibpcap=disabled \
	-Dlibssh=disabled -Dlibssh2=disabled -Dlogin_shell=enabled \
	-Dnetcf=disabled -Dnls=disabled -Dno_git=false -Dnss=disabled \
	-Dnumactl=enabled -Dnumad=disabled -Dopenwsman=enabled \
	-Dpciaccess=enabled -Dpm_utils=disabled -Dpolkit=disabled \
	-Dreadline=enabled -Dremote_default_mode=legacy -Drpath=disabled \
	-Dsanlock=disabled -Dsasl=disabled -Dsecdriver_apparmor=disabled \
	-Dsecdriver_selinux=disabled -Dselinux=disabled -Dstorage_dir=enabled \
	-Dstorage_disk=enabled -Dstorage_fs=enabled -Dstorage_gluster=disabled \
	-Dstorage_iscsi=disabled -Dstorage_iscsi_direct=disabled \
	-Dstorage_lvm=enabled -Dstorage_mpath=enabled -Dstorage_rbd=disabled \
	-Dstorage_scsi=enabled -Dstorage_sheepdog=disabled \
	-Dstorage_vstorage=disabled -Dstorage_zfs=disabled \
	-Dsysctl_config=enabled -Dsystem=false -Dtest_coverage=false \
	-Dtests=disabled -Dudev=enabled -Dwireshark_dissector=disabled \
	-Dyajl=enabled
	cd $(tgt_src_dir) && ninja -C build
	cd $(tgt_src_dir) && ninja -C build install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

gnutls.chroot: glibc.chroot nettle.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr --disable-guile \
	--with-nettle-mini --with-included-libtasn1 --with-included-unistring \
	--without-p11-kit
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

nettle.chroot: glibc.chroot openssl.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr --enable-mini-gmp
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

yajl.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure -p /usr
	$(MAKE) --jobs=1 --directory=$(tgt_src_dir)
	$(MAKE) --jobs=1 --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

tokyocabinet.chroot: glibc.chroot bzip2.chroot zlib.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

fuse.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr \
	--sysconfdir=/etc --localstatedir=/var
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir)/include install
	$(MAKE) --directory=$(tgt_src_dir)/lib install
	$(MAKE) --directory=$(tgt_src_dir)/doc install
	$(MAKE) --directory=$(tgt_src_dir)/util install-binPROGRAMS
	$(MAKE) --directory=$(tgt_src_dir) install-pkgconfigDATA
	$(INSTALL) $(tgt_src_dir)/util/mount.fuse /sbin/mount.fuse
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

db.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir)/build_unix && ../dist/configure --prefix=/usr
	$(MAKE) --directory=$(tgt_src_dir)/build_unix
	$(MAKE) --directory=$(tgt_src_dir)/build_unix install_setup
	$(MAKE) --directory=$(tgt_src_dir)/build_unix install_include
	$(MAKE) --directory=$(tgt_src_dir)/build_unix install_lib
	$(MAKE) --directory=$(tgt_src_dir)/build_unix install_utilities
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

snappy.chroot: glibc.chroot gcc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(RM) $(tgt_src_dir)/build
	$(MKDIR) $(tgt_src_dir)/build
	cd $(tgt_src_dir)/build && cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr \
	-DBUILD_SHARED_LIBS=ON -DBUILD_STATIC_LIBS=OFF \
	-DBUILD_TESTS=OFF -DSNAPPY_BUILD_TESTS=OFF ../
	cd $(tgt_src_dir)/build && cmake ../
	$(MAKE) --directory=$(tgt_src_dir)/build
	$(MAKE) --directory=$(tgt_src_dir)/build install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

fence-agents.chroot: glibc.chroot nss.chroot Python.chroot perl.chroot \
	openwsman.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(QUIET) if [ ! -f "$(tgt_src_dir)/configure" ]; then \
	  $(SED) -i 's/\/log\/cluster/\/log/' $(tgt_src_dir)/configure.ac; \
	  cd $(tgt_src_dir) && ./autogen.sh; \
	fi
	cd $(tgt_src_dir) && ./configure --prefix=/usr --localstatedir=/var \
	--sysconfdir=/etc
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

curl.chroot: glibc.chroot openssl.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr --disable-static \
	--without-libssh2 --without-libidn
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

fio.chroot: glibc.chroot libaio.chroot numactl.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr --disable-native
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) mandir=/usr/share/man install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

bash.chroot: glibc.chroot ncurses.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr \
	--exec-prefix=/ --with-curses
	$(MAKE) --directory=$(tgt_src_dir) TERMCAP_LIB="-lncursesw"
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

open-fcoe.chroot: glibc.chroot open-lldp.chroot libpciaccess.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(QUIET) if [ ! -f "$(tgt_src_dir)/libHBAAPI/configure" ]; then \
	  $(SED) -i 's/-Werror//' $(tgt_src_dir)/libHBAAPI/configure.ac; \
	  cd $(tgt_src_dir)/libHBAAPI && ./bootstrap.sh; \
	fi
	cd $(tgt_src_dir)/libHBAAPI && ./configure --prefix=/usr \
	--sysconfdir=/etc
	$(MAKE) --directory=$(tgt_src_dir)/libHBAAPI
	$(MAKE) --directory=$(tgt_src_dir)/libHBAAPI install-libLTLIBRARIES
	$(MAKE) --directory=$(tgt_src_dir)/libHBAAPI install-data
	$(QUIET) if [ ! -f "$(tgt_src_dir)/libhbalinux/configure" ]; then \
	  $(SED) -i 's/-Werror//' $(tgt_src_dir)/libhbalinux/configure.ac; \
	  cd $(tgt_src_dir)/libhbalinux && ./bootstrap.sh; \
	fi
	cd $(tgt_src_dir)/libhbalinux && ./configure --prefix=/usr \
	--sysconfdir=/etc
	$(MAKE) --directory=$(tgt_src_dir)/libhbalinux
	$(MAKE) --directory=$(tgt_src_dir)/libhbalinux install
	$(QUIET) if [ ! -f "$(tgt_src_dir)/fcoe-utils/configure" ]; then \
	  $(SED) -i 's/-Werror//' $(tgt_src_dir)/fcoe-utils/Makefile.am; \
	  cd $(tgt_src_dir)/fcoe-utils && ./bootstrap.sh; \
	fi
	cd $(tgt_src_dir)/fcoe-utils && ./configure --prefix=/usr \
	--sysconfdir=/etc
	$(MAKE) --directory=$(tgt_src_dir)/fcoe-utils \
	LIBS="-lHBAAPI -ldl -lhbalinux -lrt"
	$(MAKE) --directory=$(tgt_src_dir)/fcoe-utils install-exec
	$(MAKE) --directory=$(tgt_src_dir)/fcoe-utils install-man
	$(INSTALL) $(tgt_src_dir)/fcoe-utils/contrib/*.sh /usr/sbin/
	$(INSTALL) $(tgt_src_dir)/fcoe-utils/debug/*.sh /usr/sbin/
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

open-lldp.chroot: glibc.chroot libconfig.chroot libnl.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(SED) -i 's/^AC_FUNC_MALLOC/dnl AC_FUNC_MALLOC/' \
	$(tgt_src_dir)/configure.ac
	$(SED) -i 's/^AC_FUNC_REALLOC/dnl AC_FUNC_REALLOC/' \
	$(tgt_src_dir)/configure.ac
	$(SED) -i 's/foreign/foreign subdir-objects/' \
	$(tgt_src_dir)/configure.ac
	$(SED) -i 's/-Werror//' $(tgt_src_dir)/Makefile.am
	$(SED) -i 's/-Werror//' $(tgt_src_dir)/configure.ac
	$(QUIET) if [ ! -f "$(tgt_src_dir)/configure" ]; then \
	  cd $(tgt_src_dir) && ./bootstrap.sh; \
	fi
	cd $(tgt_src_dir) && ./configure --prefix=/usr
	$(MAKE) --directory=$(tgt_src_dir) CC="gcc -fgnu89-inline"
	$(MAKE) --directory=$(tgt_src_dir) install-exec
	$(MAKE) --directory=$(tgt_src_dir) install-lldpad_includeHEADERS
	$(MAKE) --directory=$(tgt_src_dir) install-man 
	$(MAKE) --directory=$(tgt_src_dir) install-pkgconfigDATA
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

libconfig.chroot: glibc.chroot gcc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && CXX="g++ -std=c++98" ./configure --prefix=/usr
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

libnl.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

libpciaccess.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

linux_firmware.chroot:
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(MKDIR) /lib/firmware
	$(CP) $(tgt_src_dir)/WHENCE /lib/firmware/
	$(CP) -r $(tgt_src_dir)/bnx2* /lib/firmware/
	$(CP) $(tgt_src_dir)/LICENCE.chelsio_firmware /lib/firmware/
	$(CP) -r $(tgt_src_dir)/cxgb* /lib/firmware/
	$(CP) -r $(tgt_src_dir)/qlogic /lib/firmware/
	$(CP) -r $(tgt_src_dir)/cbfw* /lib/firmware/
	$(CP) -r $(tgt_src_dir)/ctfw* /lib/firmware/
	$(CP) -r $(tgt_src_dir)/ct2fw* /lib/firmware/
	$(CP) -r $(tgt_src_dir)/qed /lib/firmware/
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

dlm.chroot: glibc.chroot corosync.chroot libxml2.chroot pacemaker.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(MAKE) --directory=$(tgt_src_dir) USE_SD_NOTIFY=no
	$(SED) -e '/$$(INSTALL) -d $$(DESTDIR)\/$$(MANDIR)\/man8/ s/^#*/#/' \
	-i $(tgt_src_dir)/fence/Makefile
	$(MAKE) --directory=$(tgt_src_dir)/fence
	$(MAKE) --directory=$(tgt_src_dir) \
	UDEVDIR="/usr/lib/udev/rules.d" install
	$(MAKE) --directory=$(tgt_src_dir)/fence install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

ipmitool.chroot: glibc.chroot openssl.chroot ncurses.chroot readline.chroot \
	libedit.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(call apply_pkg_patch)
	cd $(tgt_src_dir) && \
	LIBS="-lncursesw -lreadline -ledit" \
	./configure --prefix=/usr --enable-intf-lan --enable-intf-lanplus
	$(MAKE) --directory=$(tgt_src_dir) \
	LIBS="-lreadline -lncursesw -lcrypto -ledit"
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

sysklogd.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(QUIET) if [ ! -f "$(tgt_src_dir)/configure" ]; then \
	  cd $(tgt_src_dir) && ./autogen.sh; \
	fi
	cd $(tgt_src_dir) && ./configure --prefix=/usr
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

less.chroot: glibc.chroot ncurses.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr --sysconfdir=/etc
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

irqbalance.chroot: glibc.chroot glib.chroot ncurses.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(QUIET) if [ ! -f "$(tgt_src_dir)/configure" ]; then \
	  cd $(tgt_src_dir) && ./autogen.sh; \
	fi
	cd $(tgt_src_dir) && NCURSESW_CFLAGS="-D_GNU_SOURCE -D_DEFAULT_SOURCE" \
	NCURSESW_LIBS="-lncursesw" ./configure --prefix=/usr --enable-numa \
	--without-systemd --without-libcap-ng
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

ethtool.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

postgresql.chroot: glibc.chroot zlib.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr --without-readline
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir)/src/bin install
	$(MAKE) --directory=$(tgt_src_dir)/src/include install
	$(MAKE) --directory=$(tgt_src_dir)/src/interfaces/libpq install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

mysql.chroot: glibc.chroot ncurses.chroot busybox.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(LN) /bin/busybox /usr/bin/ps
	cd $(tgt_src_dir) && CXX="g++ -std=c++98" \
	./configure --prefix=/usr --without-server --without-bench \
	--enable-thread-safe-client
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir)/libmysql install
	$(MAKE) --directory=$(tgt_src_dir)/libmysql_r install
	$(MAKE) --directory=$(tgt_src_dir)/scripts install-binSCRIPTS
	$(MAKE) --directory=$(tgt_src_dir)/include install
	$(MAKE) --directory=$(tgt_src_dir)/extra install
	$(RM) /usr/bin/ps
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

infiniband-diags.chroot: perl_install = $(wildcard /usr/lib/perl5/5.*)
infiniband-diags.chroot: glibc.chroot libibumad.chroot libibverbs.chroot \
	libibmad.chroot opensm.chroot glib.chroot eudev.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr --sysconfdir=/etc \
	--localstatedir=/var --with-perl-installdir=$(perl_install) \
	--with-ibpath_override=/usr/sbin
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install-data
	$(MAKE) --directory=$(tgt_src_dir) install-sbinPROGRAMS
	$(MAKE) --directory=$(tgt_src_dir) install-sbinSCRIPTS
	$(MAKE) --directory=$(tgt_src_dir)/libibnetdisc install-libLTLIBRARIES
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

libibmad.chroot: glibc.chroot libibumad.chroot libibverbs.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr --sysconfdir=/etc \
	--localstatedir=/var
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

perftest.chroot: glibc.chroot infiniband-diags.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(QUIET) if [ ! -f "$(tgt_src_dir)/configure" ]; then \
	  cd $(tgt_src_dir) && ./autogen.sh; \
	fi
	cd $(tgt_src_dir) && ./configure --prefix=/usr
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

nrpe.chroot: glibc.chroot openssl.chroot e2fsprogs.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr --sysconfdir=/etc \
	--enable-ssl --enable-command-args --with-piddir=/var/run
	$(MAKE) --directory=$(tgt_src_dir) all
	$(MAKE) --directory=$(tgt_src_dir) NAGIOS_INSTALL_OPTS="" \
	NRPE_INSTALL_OPTS="" install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

bcache-tools.chroot: glibc.chroot util-linux.chroot openssl.chroot eudev.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(call apply_pkg_patch)
	$(MAKE) --directory=$(tgt_src_dir) \
	LDLIBS="-lssl -lcrypto -ldl -lblkid -luuid" \
	make-bcache probe-bcache bcache-register
	$(MAKE) --directory=$(tgt_src_dir) \
	LDLIBS="-lssl -lcrypto -ldl -lblkid -luuid" \
	CFLAGS+="-std=gnu99" bcache-super-show
	$(INSTALL) -m 0755 $(tgt_src_dir)/make-bcache \
	/usr/sbin/make-bcache
	$(INSTALL) -m 0755 $(tgt_src_dir)/bcache-super-show \
	/usr/sbin/bcache-super-show
	$(INSTALL) -m 0644 $(tgt_src_dir)/69-bcache.rules \
	/usr/lib/udev/rules.d/69-bcache.rules
	$(SED) -i '/kmod load bcache/ s/^#*/#/' \
	/usr/lib/udev/rules.d/69-bcache.rules
	$(INSTALL) -m 0755 $(tgt_src_dir)/probe-bcache \
	/usr/lib/udev/probe-bcache
	$(INSTALL) -m 0755 $(tgt_src_dir)/bcache-register \
	/usr/lib/udev/bcache-register
	$(INSTALL) -m 0644 $(tgt_src_dir)/*.8 /usr/share/man/man8/
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

EnhanceIO.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(call apply_pkg_patch)
	$(INSTALL) -m 0755 $(tgt_src_dir)/CLI/eio_cli /usr/sbin/
	$(INSTALL) -m 0644 $(tgt_src_dir)/CLI/eio_cli.8 /usr/share/man/man8/
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

util-linux.chroot: glibc.chroot ncurses.chroot zlib.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr --disable-most-builds \
	--disable-bash-completion --with-ncursesw --disable-silent-rules \
	--without-udev --disable-setpriv --without-python
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install-usrlib_execLTLIBRARIES
	$(MAKE) --directory=$(tgt_src_dir) install-data-recursive
	$(INSTALL) -m 0755 $(tgt_src_dir)/.libs/blkid /usr/sbin/
	$(INSTALL) -m 0755 $(tgt_src_dir)/.libs/wipefs /usr/sbin/
	$(INSTALL) -m 0755 $(tgt_src_dir)/.libs/lsblk /usr/bin/
	$(INSTALL) -m 0755 $(tgt_src_dir)/.libs/lscpu /usr/bin/
	$(INSTALL) -m 0755 $(tgt_src_dir)/taskset /usr/bin/
	$(INSTALL) -m 0755 $(tgt_src_dir)/flock /usr/bin/
	$(INSTALL) -m 0755 $(tgt_src_dir)/blkdiscard /usr/bin/
	$(INSTALL) -m 0755 $(tgt_src_dir)/agetty /sbin/
	$(INSTALL) -m 0755 $(tgt_src_dir)/mkfs /usr/sbin/
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

thin-provisioning-tools.chroot: glibc.chroot gcc.chroot expat.chroot \
	boost.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(QUIET) if [ ! -f "$(tgt_src_dir)/configure" ]; then \
	  cd $(tgt_src_dir) && autoconf; \
	fi
	cd $(tgt_src_dir) && CXX="g++ -std=c++98 -D_GLIBCXX_BITSET" \
	./configure --prefix=/usr
	$(MAKE) --directory=$(tgt_src_dir) V=""
	$(MAKE) --directory=$(tgt_src_dir) install MANDIR=/usr/share/man
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

expat.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr --without-docbook \
	--without-xmlwf
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

boost.chroot: glibc.chroot gcc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(QUIET) if [ ! -f "$(tgt_src_dir)/b2" ]; then \
	  cd $(tgt_src_dir) && ./bootstrap.sh --prefix=/usr; \
	fi
	cd $(tgt_src_dir) && ./b2 install --without-atomic --without-chrono \
	--without-context --without-contract --without-coroutine \
	--without-date_time --without-exception --without-fiber \
	--without-filesystem --without-graph --without-graph_parallel \
	--without-iostreams --without-locale --without-log --without-math \
	--without-mpi --witout-program_options --without-python \
	--without-random --without-regex --without-serialization \
	--without-stacktrace --without-system --without-test --without-timer \
	--witout-type_erasure --without-wave
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

btier.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(CC) -Wall -D_FILE_OFFSET_BITS=64 $(tgt_src_dir)/cli/btier_setup.c \
	-o $(tgt_src_dir)/cli/btier_setup
	$(CC) -Wall -D_FILE_OFFSET_BITS=64 $(tgt_src_dir)/cli/btier_inspect.c \
	-o $(tgt_src_dir)/cli/btier_inspect
	$(CC) -Wall $(tgt_src_dir)/tools/writetest.c -o \
	$(tgt_src_dir)/tools/writetest
	$(CC) -Wall $(tgt_src_dir)/tools/show_block_details.c \
	-o $(tgt_src_dir)/tools/show_block_details
	$(INSTALL) -D -m 755 $(tgt_src_dir)/cli/btier_setup \
	/usr/sbin/btier_setup
	$(INSTALL) -D -m 755 $(tgt_src_dir)/cli/btier_inspect \
	/usr/sbin/btier_inspect
	$(INSTALL) -D -m 644 $(tgt_src_dir)/man/btier_setup.1 \
	usr/share/man/man1/btier_setup.1
	$(INSTALL) -D -m 644 $(tgt_src_dir)/man/btier_inspect.1 \
	/usr/share/man/man1/btier_inspect.1
	$(INSTALL) -D -m 755 \
	$(tgt_src_dir)/tools/contributed/migrate_blocks_freq.py \
	/usr/sbin/migrate_blocks_freq.py
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

librdmacm.chroot: glibc.chroot libibverbs.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr --sysconfdir=/etc \
	--localstatedir=/var --mandir=/usr/share/man
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

sysstat.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr
	$(MAKE) --directory=$(tgt_src_dir)
	$(INSTALL) -m 0755 $(tgt_src_dir)/iostat /usr/bin/
	$(INSTALL) -m 0755 $(tgt_src_dir)/mpstat /usr/bin/
	$(INSTALL) -m 0755 $(tgt_src_dir)/pidstat /usr/bin/
	$(INSTALL) -m 0755 $(tgt_src_dir)/cifsiostat /usr/bin/
	$(INSTALL) -m 0755 $(tgt_src_dir)/sar /usr/bin/
	$(INSTALL) -m 0755 $(tgt_src_dir)/sadc /usr/bin/
	$(INSTALL) -m 0755 $(tgt_src_dir)/sadf /usr/bin/
	$(INSTALL) -m 0644 $(tgt_src_dir)/man/iostat.1 /usr/share/man/man1/
	$(INSTALL) -m 0644 $(tgt_src_dir)/man/mpstat.1 /usr/share/man/man1/
	$(INSTALL) -m 0644 $(tgt_src_dir)/man/pidstat.1 /usr/share/man/man1/
	$(INSTALL) -m 0644 $(tgt_src_dir)/man/cifsiostat.1 /usr/share/man/man1/
	$(INSTALL) -m 0644 $(tgt_src_dir)/man/sar.1 /usr/share/man/man1/
	$(INSTALL) -m 0644 $(tgt_src_dir)/man/sadc.8 /usr/share/man/man8/
	$(INSTALL) -m 0644 $(tgt_src_dir)/man/sadf.1 /usr/share/man/man1/
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

pciutils.chroot: glibc.chroot zlib.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(MAKE) --directory=$(tgt_src_dir) SHARED=yes PREFIX=/usr
	$(MAKE) --directory=$(tgt_src_dir) SHARED=yes PREFIX=/usr install
	$(MAKE) --directory=$(tgt_src_dir) SHARED=yes PREFIX=/usr install-lib
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

tar.chroot: glibc.chroot acl.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && am__tar='tar chf - "$$tardir"' \
	am__untar='tar xf -' am_cv_prog_tar_ustar='fake_ustar_cmd' \
	FORCE_UNSAFE_CONFIGURE=1 ./configure --prefix=/usr --without-selinux
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

net-snmp.chroot: glibc.chroot gcc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(call apply_pkg_patch)
	cd $(tgt_src_dir) && ./configure --prefix=/usr \
	--with-default-snmp-version="3" --with-sys-contact="@@no.where" \
	--with-sys-location="Unknown" --with-logfile="/var/log/snmpd.log" \
	--with-persistent-directory="/var/lib/net-snmp" \
	--without-perl-modules --enable-embedded-perl --disable-perl-cc-checks \
	--without-python-modules --without-mysql --sysconfdir=/etc \
	--enable-minimalist --disable-deprecated \
	--with-mib-modules="ucd-snmp/diskio etherlike-mib" --disable-manuals \
	--disable-scripts --enable-ipv6 --with-features="mib_strings_all"
	$(MAKE) --jobs=1 --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

nut.chroot: glibc.chroot net-snmp.chroot libusb_compat.chroot freeipmi.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && CXX="g++ -std=c++98" \
	./configure --prefix=/usr --sysconfdir=/etc --without-dev \
	--with-serial --with-usb --with-snmp --without-cgi \
	--with-user=nutmon --with-group=nut --without-avahi \
	--with-usb-libs="-lusb" --with-snmp-libs="-lnetsnmp" \
	--with-ipmi --with-freeipmi --with-freeipmi-libs="-lfreeipmi"
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir)/common install
	$(MAKE) --directory=$(tgt_src_dir)/clients install
	$(MAKE) --directory=$(tgt_src_dir)/data install
	$(MAKE) --directory=$(tgt_src_dir)/tools install
	$(MAKE) --directory=$(tgt_src_dir)/docs install
	$(MAKE) --directory=$(tgt_src_dir)/drivers install
	$(MAKE) --directory=$(tgt_src_dir)/lib install
	$(MAKE) --directory=$(tgt_src_dir)/server install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

libusb.chroot: glibc.chroot eudev.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr
	$(MAKE) --jobs=1 --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

libusb_compat.chroot: glibc.chroot libusb.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

freeipmi.chroot: glibc.chroot libgcrypt.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && am_cv_prog_tar_ustar='fake_ustar_cmd' \
	./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var \
	--disable-init-scripts
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir)/common install
	$(MAKE) --directory=$(tgt_src_dir)/libfreeipmi install
	$(MAKE) --directory=$(tgt_src_dir)/libipmiconsole install
	$(MAKE) --directory=$(tgt_src_dir)/libipmimonitoring install
	$(MAKE) --directory=$(tgt_src_dir)/libipmidetect install
	$(MAKE) --directory=$(tgt_src_dir)/man install
	$(MAKE) --directory=$(tgt_src_dir)/bmc-info install
	$(MAKE) --directory=$(tgt_src_dir)/bmc-device install
	$(MAKE) --directory=$(tgt_src_dir)/bmc-watchdog install
	$(MAKE) --directory=$(tgt_src_dir)/ipmi-chassis install
	$(MAKE) --directory=$(tgt_src_dir)/ipmi-config install
	$(MAKE) --directory=$(tgt_src_dir)/ipmi-dcmi install
	$(MAKE) --directory=$(tgt_src_dir)/ipmi-fru install
	$(MAKE) --directory=$(tgt_src_dir)/ipmi-oem install
	$(MAKE) --directory=$(tgt_src_dir)/ipmi-pet install
	$(MAKE) --directory=$(tgt_src_dir)/ipmi-raw install
	$(MAKE) --directory=$(tgt_src_dir)/ipmi-sel install
	$(MAKE) --directory=$(tgt_src_dir)/ipmi-sensors install
	$(MAKE) --directory=$(tgt_src_dir)/ipmi-locate install
	$(MAKE) --directory=$(tgt_src_dir)/ipmiconsole install
	$(MAKE) --directory=$(tgt_src_dir)/ipmidetect install
	$(MAKE) --directory=$(tgt_src_dir)/ipmidetectd install
	$(MAKE) --directory=$(tgt_src_dir)/ipmiping install
	$(MAKE) --directory=$(tgt_src_dir)/ipmipower install
	$(MAKE) --directory=$(tgt_src_dir)/ipmiseld install
	$(MAKE) --directory=$(tgt_src_dir)/rmcpping install
	$(MAKE) --directory=$(tgt_src_dir)/contrib install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

libgcrypt.chroot: glibc.chroot libgpg-error.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

libgpg-error.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(SED) -i 's/namespace/pkg_&/' $(tgt_src_dir)/src/Makefile.{am,in} \
	$(tgt_src_dir)/src/mkstrtable.awk
	cd $(tgt_src_dir) && ./configure --prefix=/usr
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

smartmontools.chroot: glibc.chroot gcc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && CXX="g++ -std=c++98" \
	./configure --prefix=/usr --sysconfdir=/etc --with-initscriptdir=no
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install-sbinPROGRAMS
	$(MAKE) --directory=$(tgt_src_dir) install-sbinSCRIPTS
	$(MAKE) --directory=$(tgt_src_dir) install-data
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

cryptsetup.chroot: glibc.chroot libgcrypt.chroot lvm2.chroot \
	util-linux.chroot popt.chroot eudev.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr --disable-selinux \
	--with-crypto_backend=gcrypt
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

popt.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr --disable-static
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

mtx.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) prefix=/usr install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

mt-st.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) SBINDIR=/usr/sbin \
	BINDIR=/usr/bin MANDIR=/usr/share/man install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

nagios-plugins.chroot: glibc.chroot openssl.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(SED) -i -e '/gets is a security/d' $(tgt_src_dir)/gl/stdio.in.h
	cd $(tgt_src_dir) && ./configure --prefix=/usr --without-gnutls \
	--without-pgsql --without-mysql --without-dbi --without-radius \
	--without-ldap --with-ipv6 --with-perl=/usr/bin/perl \
	--with-openssl=/usr
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

libedit.chroot: glibc.chroot ncurses.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(SED) -i '/LIBS/s/"-lncurses /"-lncursesw /' $(tgt_src_dir)/configure
	cd $(tgt_src_dir) && ./configure --prefix=/usr --enable-shared
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

libmcrypt.chroot: glibc.chroot gcc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr --mandir=/usr/share/man
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

nsca.chroot: glibc.chroot libmcrypt.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr
	$(MAKE) --directory=$(tgt_src_dir)
	$(INSTALL) -m 0755 $(tgt_src_dir)/src/send_nsca /usr/sbin/
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

btrfs-progs.chroot: glibc.chroot util-linux.chroot attr.chroot zlib.chroot \
	acl.chroot e2fsprogs.chroot Python.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(QUIET) if [ ! -f "$(tgt_src_dir)/configure" ]; then \
	  cd $(tgt_src_dir) && ./autogen.sh; \
	fi
	cd $(tgt_src_dir) && ./configure --prefix=/usr --disable-documentation \
	--disable-zstd
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

attr.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr --sysconfdir=/etc
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

acl.chroot: glibc.chroot attr.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr --sysconfdir=/etc
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

htop.chroot: glibc.chroot ncurses.chroot Python.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(SED) -i 's@/usr/bin/env python$$@/usr/bin/env python3@' \
	$(tgt_src_dir)/scripts/MakeHeader.py
	cd $(tgt_src_dir) && ./autogen.sh
	cd $(tgt_src_dir) && ./configure --prefix=/usr
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install-binPROGRAMS install-man1
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

dmidecode.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(MAKE) --directory=$(tgt_src_dir) prefix=/usr
	$(MAKE) --directory=$(tgt_src_dir) install prefix=/usr
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

xmlrpc-c.chroot: glibc.chroot gcc.chroot curl.chroot libxml2.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr \
	--disable-wininet-client --disable-libwww-client --disable-cgi-server \
	--enable-curl-client --enable-libxml2-backend
	$(MAKE) --jobs=1 --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(MAKE) --directory=$(tgt_src_dir)/tools/xmlrpc
	$(INSTALL) -vD -m 755 $(tgt_src_dir)/tools/xmlrpc/xmlrpc \
	/usr/bin/xmlrpc
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

stunnel.chroot: glibc.chroot openssl.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr --sysconfdir=/etc \
	--with-ssl="/usr" --with-threads=fork
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir)/src install-exec
	$(MAKE) --directory=$(tgt_src_dir)/doc install-data
	$(MAKE) --directory=$(tgt_src_dir)/tools install-confDATA
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

sudo.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && VIPROG="/bin/vi" MVPROG="/bin/mv" \
	./configure --prefix=/usr --with-editor="/bin/vi" --with-env-editor
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) INSTALL_OWNER="" \
	install SUBDIRS="lib/util plugins/group_file \
	plugins/sudoers plugins/system_group src include doc"
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

rsync.chroot: glibc.chroot attr.chroot acl.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr --sysconfdir=/etc
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

eudev.chroot: glibc.chroot util-linux.chroot gperf.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(QUIET) if [ ! -f "$(tgt_src_dir)/configure" ]; then \
	  cd $(tgt_src_dir) && ./autogen.sh; \
	fi
	cd $(tgt_src_dir) && ./configure --prefix=/usr --sysconfdir=/etc \
	--disable-selinux --disable-gudev --disable-kmod --disable-silent-rules
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

gperf.chroot: glibc.chroot gcc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && CXX="g++ -std=c++98" ./configure --prefix=/usr
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

multipath-tools.chroot: glibc.chroot lvm2.chroot readline.chroot \
	eudev.chroot userspace-rcu.chroot json-c.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(SED) -i '38,51 s/^#*/#/' $(tgt_src_dir)/Makefile.inc
	$(SED) -i 's/-lreadline$$/-lreadline -lncursesw/' \
	$(tgt_src_dir)/multipathd/Makefile
	$(MAKE) --directory=$(tgt_src_dir) LIB="usr/lib"
	$(MAKE) --directory=$(tgt_src_dir) LIB="usr/lib" bindir=/usr/sbin \
	libudevdir=/usr/lib/udev install
	$(SED) -i 's/"\/sbin\//"\/usr\/sbin\//' \
	/usr/lib/udev/rules.d/66-kpartx.rules
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

json-c.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(SED) -i 's/-Werror//' $(tgt_src_dir)/Makefile.in
	cd $(tgt_src_dir) && ./configure --prefix=/usr
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

archivemount.chroot: glibc.chroot libarchive.chroot fuse.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

libarchive.chroot: glibc.chroot bzip2.chroot lzo.chroot zlib.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr --without-iconv \
	--without-lzma --without-nettle --without-openssl --without-xml2 \
	--without-expat
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

rasdaemon.chroot: glibc.chroot perl.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr --localstatedir=/var \
	--sysconfdir=/etc --enable-aer --enable-mce --enable-sqlite3 \
	--enable-extlog --enable-hisi-ns-decode --enable-non-standard \
	--enable-devlink
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

edac-utils.chroot: glibc.chroot sysfsutils.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr --mandir=/usr/share/man
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir)/src install SUBDIRS="lib util"
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

sysfsutils.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr --mandir=/usr/share/man
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

sqlite-autoconf.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

libpcap.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

iftop.chroot: glibc.chroot libpcap.chroot ncurses.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(SED) -i 's/\$$curseslib.h/ncurses.h/' $(tgt_src_dir)/configure
	cd $(tgt_src_dir) && ./configure --prefix=/usr
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

iperf2.chroot: glibc.chroot gcc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && CXX="g++ -std=c++98" ./configure --prefix=/usr
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

iperf3.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

nmon.chroot: glibc.chroot gcc.chroot ncurses.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(CC) -o $(tgt_src_dir)/nmon $(tgt_src_dir)/lmon.c -g -O3 -Wall \
	-lncursesw -lm -D X86
	$(INSTALL) -D -m 0755 -v $(tgt_src_dir)/nmon /usr/sbin/nmon
	$(RM) $(tgt_src_dir)/nmon
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

munin-c.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(QUIET) if [ ! -f "$(tgt_src_dir)/configure" ]; then \
	  $(SED) -i 's/-Werror//' $(tgt_src_dir)/configure.ac; \
	  cd $(tgt_src_dir) && autoreconf -i -I m4; \
	fi
	cd $(tgt_src_dir) && ./configure --prefix=/usr
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(MKDIR) /etc/munin/plugins
	for i in $$(/usr/libexec/munin-c/munin-plugins-c listplugins); do \
	  $(LN) /usr/libexec/munin-c/munin-plugins-c \
	  /etc/munin/plugins/$$i; \
	done
	$(LN) /usr/libexec/munin-c/munin-plugins-c \
	/etc/munin/plugins/memory
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

open-iscsi.chroot: glibc.chroot open-isns.chroot util-linux.chroot kmod.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(MAKE) --directory=$(tgt_src_dir) LIBADD="-lkmod" NO_SYSTEMD=1 \
	OPTFLAGS="-Os -Wno-format-truncation -DNO_SYSTEMD" \
	PKG_CONFIG="pkg-config" user
	$(MAKE) --directory=$(tgt_src_dir) install_programs
	$(MAKE) --directory=$(tgt_src_dir) install_doc
	$(MAKE) --directory=$(tgt_src_dir) install_etc
	$(MAKE) --directory=$(tgt_src_dir) install_iface
	$(MAKE) --directory=$(tgt_src_dir) install_libopeniscsiusr
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

open-isns.chroot: glibc.chroot openssl.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(SED) -i '/isnsd\.service/d' $(tgt_src_dir)/Makefile.in
	$(SED) -i '/isnsd\.socket/d' $(tgt_src_dir)/Makefile.in
	cd $(tgt_src_dir) && ./configure --prefix=/usr --enable-shared \
	--disable-static
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install SYSTEMDDIR=""
	$(MAKE) --directory=$(tgt_src_dir) install_hdrs
	$(MAKE) --directory=$(tgt_src_dir) install_lib
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

coreutils.chroot: glibc.chroot perl.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && FORCE_UNSAFE_CONFIGURE=1 ./configure --prefix=/usr
	$(MAKE) --directory=$(tgt_src_dir)
	$(INSTALL) -m 0755 $(tgt_src_dir)/src/df /bin/df
	$(INSTALL) -m 0755 $(tgt_src_dir)/src/dd /bin/dd
	$(INSTALL) -m 0755 $(tgt_src_dir)/src/pr /bin/pr
	$(INSTALL) -m 0755 $(tgt_src_dir)/src/readlink /usr/bin/readlink
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

open-vm-tools.chroot: glibc.chroot gcc.chroot glib.chroot libdnet.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(call apply_pkg_patch)
	$(SED) -i '/CFLAGS/s/-Werror//' $(tgt_src_dir)/configure
	cd $(tgt_src_dir) && ./configure --prefix=/usr --disable-deploypkg \
	--disable-grabbitmqproxy --disable-vgauth --without-root-privileges \
	--without-kernel-modules --without-gtk2 --without-gtkmm --without-pam \
	--without-xmlsecurity --without-xerces --without-procps --without-icu \
	--without-x
	$(MAKE) --directory=$(tgt_src_dir)
	$(SED) -i 's/-$$(LN_S) $$(DESTDIR)$$(sbindir)/-$$(LN_S) $$(sbindir)/g' \
	$(tgt_src_dir)/hgfsmounter/Makefile
	$(MAKE) --directory=$(tgt_src_dir) install pamdir=""
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

libdnet.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr \
	--mandir=/usr/share/man --with-pic
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

libffi.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

openwsman.chroot: glibc.chroot gcc.chroot Python.chroot libxml2.chroot \
	openssl.chroot swig.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(SED) -i "s/2.6.1/2.7.0/" $(tgt_src_dir)/configure.ac
	$(SED) -i "s/OPENWSMAN_MINOR=6/OPENWSMAN_MINOR=7/" \
	$(tgt_src_dir)/configure.ac
	$(SED) -i "s/OPENWSMAN_PATCH=1/OPENWSMAN_PATCH=0/" \
	$(tgt_src_dir)/configure.ac
	$(QUIET) if [ ! -f "$(tgt_src_dir)/configure" ]; then \
	  cd $(tgt_src_dir) && ./autoconfiscate.sh \
	  --ignore-deprecation-warning; \
	fi
	$(SED) -i "s/\$$EGREP/egrep/g" $(tgt_src_dir)/configure
	$(SED) -i "s/python-config/python3-config/g" $(tgt_src_dir)/configure
	cd $(tgt_src_dir) && CXX="g++ -std=c++98" ./configure --prefix=/usr \
	--disable-pam --enable-python=yes --disable-server --disable-plugins \
	--disable-more-warnings --disable-silent-rules
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir)/include install
	$(MAKE) --directory=$(tgt_src_dir)/src install
	$(MAKE) --directory=$(tgt_src_dir)/doc install
	$(MAKE) --directory=$(tgt_src_dir)/bindings install
	$(MAKE) --directory=$(tgt_src_dir) install-data-local
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

swig.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr --without-popen \
	--without-pcre --without-maximum-compile-warnings --without-alllang
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

userspace-rcu.chroot: glibc.chroot gcc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

tzdata.chroot: zoneinfo = /usr/share/zoneinfo
tzdata.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(MKDIR) -pv $(zoneinfo)/{posix,right}
	$(QUIET) cd $(tgt_src_dir) && for tz in etcetera southamerica \
	  northamerica europe africa antarctica asia australasia \
	  backward pacificnew systemv factory; do \
	  $(ZIC) -L /dev/null -d $(zoneinfo) -y "sh yearistype.sh" $${tz}; \
	  $(ZIC) -L /dev/null -d $(zoneinfo)/posix \
	  -y "sh yearistype.sh" $${tz}; \
	  $(ZIC) -L leapseconds -d $(zoneinfo)/right \
	  -y "sh yearistype.sh" $${tz}; \
	done
	$(CP) -v $(tgt_src_dir)/zone.tab $(zoneinfo)/
	$(CP) -v $(tgt_src_dir)/zone1970.tab $(zoneinfo)/
	$(CP) -v $(tgt_src_dir)/iso3166.tab $(zoneinfo)/
	$(ZIC) -d $(zoneinfo) -p America/New_York
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

nvme-cli.chroot: glibc.chroot eudev.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(QUIET) if ! $(GREP) -q no-format-truncation \
	  $(tgt_src_dir)/Makefile; then \
	  $(SED) -ri 's/^(CFLAGS.*\+=.*)/\1 -Wno-format-truncation/' \
	  $(tgt_src_dir)/Makefile; \
	fi
	$(MAKE) --directory=$(tgt_src_dir) PREFIX=/usr LIBUDEV=0
	$(MAKE) --directory=$(tgt_src_dir) install-man PREFIX=/usr
	$(MAKE) --directory=$(tgt_src_dir) install-bin PREFIX=/usr
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

freetype.chroot: glibc.chroot bzip2.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr --with-harfbuzz=no \
	--with-png=no --enable-freetype-config --disable-static
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(RM) /usr/share/man/man1/freetype-config.1
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

ledmon.chroot: glibc.chroot gcc.chroot sg3_utils.chroot eudev.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(MAKE) --jobs=1 --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

nvmetcli.chroot: glibc.chroot Python.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && python3 ./setup.py install --prefix=/usr
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

sed.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

bc.chroot: glibc.chroot readline.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(ECHO) -e "#! /bin/bash\nsed -e '1   s/^/{\"/' -e 's/$$/\",/'" \
	"-e '2,$$ s/^/\"/' -e '$$ d' -i libmath.h\nsed -e '$$ s/$$/0}/'" \
	"-i libmath.h" > $(tgt_src_dir)/bc/fix-libmath_h
	$(SED) -i -e '/flex/s/as_fn_error/: ;; # &/' $(tgt_src_dir)/configure
	cd $(tgt_src_dir) && ./configure --prefix=/usr --with-readline \
	--mandir=/usr/share/man --infodir=/usr/share/info
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

libtool.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

etckeeper.chroot: git.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(MAKE) --directory=$(tgt_src_dir) etckeeper.version
	$(MKDIR) /etc/etckeeper/ /var/cache/etckeeper/
	$(CP) -Rp $(tgt_src_dir)/*.d /etc/etckeeper/
	$(INSTALL) -m 0644 $(tgt_src_dir)/etckeeper.conf /etc/etckeeper/
	$(INSTALL) -m 0755 $(tgt_src_dir)/etckeeper /usr/bin/
	$(INSTALL) -m 0644 $(tgt_src_dir)/etckeeper.8 /usr/share/man/man8/
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

git.chroot: glibc.chroot curl.chroot expat.chroot zlib.chroot openssh.chroot \
	perl.chroot Python.chroot openssl.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr --sysconfdir=/etc \
	--with-openssl --with-curl --with-expat --without-libpcre \
	--without-tcltk
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

findutils.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(QUIET) if ! $(GREP) -q _IO_IN_BACKUP \
	  $(tgt_src_dir)/gl/lib/stdio-impl.h; then \
	  $(SED) -i 's/IO_ftrylockfile/IO_EOF_SEEN/' \
	  $(tgt_src_dir)/gl/lib/*.c; \
	  $(SED) -i '/unistd/a #include <sys/sysmacros.h>' \
	  $(tgt_src_dir)/gl/lib/mountlist.c; \
	  $(ECHO) "#define _IO_IN_BACKUP 0x100" >> \
	  $(tgt_src_dir)/gl/lib/stdio-impl.h; \
	fi
	cd $(tgt_src_dir) && ./configure --prefix=/usr
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

nfs-utils.chroot: glibc.chroot rpcbind.chroot libevent.chroot keyutils.chroot \
	sqlite-autoconf.chroot lvm2.chroot libnfsidmap.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr --without-tcp-wrappers \
	--disable-gss
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

rpcbind.chroot: glibc.chroot libtirpc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr \
	--bindir=/sbin --sbindir=/sbin --with-rpcuser=root \
	--enable-warmstarts --without-systemdsystemunitdir
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

libtirpc.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr --sysconfdir=/etc \
	--disable-static --disable-gssapi
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

libevent.chroot: glibc.chroot openssl.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr --disable-static
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

keyutils.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(MAKE) --directory=$(tgt_src_dir) NO_ARLIB=1
	$(MAKE) --directory=$(tgt_src_dir) NO_ARLIB=1 LIBDIR=/usr/lib install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

libnfsidmap.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr --sysconfdir=/etc \
	--disable-static
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

hdparm.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

kbd.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(call apply_pkg_patch)
	$(SED) -i 's/\(RESIZECONS_PROGS=\)yes/\1no/g' $(tgt_src_dir)/configure
	$(SED) -i 's/resizecons.8 //' $(tgt_src_dir)/docs/man/man8/Makefile.in
	cd $(tgt_src_dir) && PKG_CONFIG_PATH=/tools/lib/pkgconfig \
	./configure --prefix=/usr --disable-vlock
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

pcre.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr --disable-static
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

nginx.chroot: glibc.chroot pcre.chroot zlib.chroot openssl.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/var/lib/nginx \
	--sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf \
	--pid-path=/var/run/nginx.pid \
	--error-log-path=/var/log/nginx/error.log \
	--http-log-path=/var/log/nginx/access.log \
	--with-http_ssl_module
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

dosfstools.chroot: glibc.chroot eudev.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

lsof.chroot: glibc.chroot libtirpc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./Configure -n linux
	$(MAKE) --directory=$(tgt_src_dir) CFGL="-L./lib -llsof -ltirpc"
	$(INSTALL) -v -m 0755 $(tgt_src_dir)/lsof /usr/bin/
	$(INSTALL) -v -m 0644 $(tgt_src_dir)/lsof.8 /usr/share/man/man8/
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

blktrace.chroot: glibc.chroot Python.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) \
	prefix=/usr mandir=/usr/share/man install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

hwloc.chroot: glibc.chroot libxml2.chroot ncurses.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

mstflint.chroot: glibc.chroot openssl.chroot libibmad.chroot Python.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

lshw.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

iozone3.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(MAKE) --directory=$(tgt_src_dir)/src/current linux-AMD64
	$(INSTALL) -m 0755 $(tgt_src_dir)/src/current/iozone /usr/bin/
	$(INSTALL) -m 0755 $(tgt_src_dir)/src/current/fileop /usr/bin/
	$(INSTALL) -m 0755 $(tgt_src_dir)/src/current/pit_server /usr/bin/
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

telegraf.chroot:
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(INSTALL) -m 0755 $(tgt_src_dir)/usr/bin/telegraf.upx \
	/usr/bin/telegraf
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

sbd.chroot: glibc.chroot glib.chroot libqb.chroot corosync.chroot \
	pacemaker.chroot libxml2.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(QUIET) if [ ! -f "$(tgt_src_dir)/configure" ]; then \
	  cd $(tgt_src_dir) && ./autogen.sh; \
	fi
	cd $(tgt_src_dir) && ./configure --prefix=/usr --sysconfdir=/etc \
	--localstatedir=/var --enable-shared-disk
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

screen.chroot: glibc.chroot ncurses.chroot Linux-PAM.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr --enable-pam \
	--enable-telnet --enable-colors256 --enable-rxvt_osc \
	--with-socket-dir=/run/screen --with-sys-screenrc=/etc/screenrc
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(INSTALL) -m 0644 $(tgt_src_dir)/etc/etcscreenrc /etc/screenrc
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

lftp.chroot: glibc.chroot openssl.chroot readline.chroot ncurses.chroot \
	zlib.chroot expat.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(SED) -i 's/ncurses;/ncursesw;/' $(tgt_src_dir)/configure
	cd $(tgt_src_dir) && ./configure --prefix=/usr --without-gnutls
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

ndctl.chroot: glibc.chroot eudev.chroot util-linux.chroot json-c.chroot \
	keyutils.chroot kmod.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(QUIET) if [ ! -f "$(tgt_src_dir)/configure" ]; then \
	  cd $(tgt_src_dir) && ./autogen.sh; \
	fi
	cd $(tgt_src_dir) && ./configure --prefix=/usr --sysconfdir=/etc \
	--without-bash --without-systemd --with-keyutils --disable-docs
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install-exec
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

kmod.chroot: glibc.chroot zlib.chroot openssl.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr --sysconfdir=/etc \
	--without-xz --with-zlib --without-openssl
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install-exec
	$(MAKE) --directory=$(tgt_src_dir) install-includeHEADERS
	$(MAKE) --directory=$(tgt_src_dir) install-pkgconfigDATA
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

docbook-xsl-nons.chroot: docbook = /usr/share/xml/docbook
docbook-xsl-nons.chroot: stylesheets = $(docbook)/xsl-stylesheets-nons-1.79.2
docbook-xsl-nons.chroot: libxml2.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(call apply_pkg_patch)
	$(INSTALL) -v -m 0755 -d $(stylesheets)
	cd $(tgt_src_dir) && $(CP) -v -R VERSION assembly common eclipse epub \
	epub3 extensions fo highlighting html htmlhelp images javahelp lib \
	manpages params profiling roundtrip slides template tests tools \
	webhelp website xhtml xhtml-1_1 xhtml5 $(stylesheets)/
	$(LN) VERSION $(stylesheets)/VERSION.xsl
	$(INSTALL) -v -m 0644 -D $(tgt_src_dir)/README \
	/usr/share/doc/docbook-xsl-nons-1.79.2/README.txt
	$(INSTALL) -v -m 0644 $(tgt_src_dir)/RELEASE-NOTES* \
	$(tgt_src_dir)/NEWS* /usr/share/doc/docbook-xsl-nons-1.79.2
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

acpid.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(INSTALL) -v -m 0755 -d /etc/acpi/events
	$(SED) 's,/acpid/,/acpi/,' $(tgt_src_dir)/samples/power > \
	/etc/acpi/events/power
	$(INSTALL) -v -m 0755 $(tgt_src_dir)/samples/power.sh /etc/acpi/
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

ibutils.chroot: glibc.chroot opensm.chroot libibumad.chroot tcl.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(call apply_pkg_patch)
	cd $(tgt_src_dir) && ./autogen.sh
	cd $(tgt_src_dir) && ./configure --prefix=/usr \
	--without-tk-lib --without-graphviz-lib
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

tcl.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir)/unix && ./configure --prefix=/usr
	$(MAKE) --directory=$(tgt_src_dir)/unix
	$(MAKE) --directory=$(tgt_src_dir)/unix mandir=/usr/share/man install
	$(CHMOD) -v u+w /usr/lib/libtcl8.6.so
	$(MAKE) --directory=$(tgt_src_dir)/unix install-private-headers
	$(LN) -v tclsh8.6 /usr/bin/tclsh
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

numactl.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && ./configure --prefix=/usr
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

iowatcher.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) prefix=/usr install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

iotop.chroot: glibc.chroot Python.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	cd $(tgt_src_dir) && python3 ./setup.py install --prefix=/usr
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

node_exporter.chroot:
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(INSTALL) -m 0755 $(tgt_src_dir)/node_exporter.upx \
	/usr/bin/node_exporter
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

libcap.chroot: glibc.chroot Linux-PAM.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(MAKE) --directory=$(tgt_src_dir) lib=lib
	$(MAKE) --directory=$(tgt_src_dir) lib=lib \
	PKGCONFIGDIR=/usr/lib/pkgconfig install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

sedutil.chroot: glibc.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(QUIET) if [ ! -f "$(tgt_src_dir)/configure" ]; then \
	  cd $(tgt_src_dir) && autoreconf --install; \
	fi
	cd $(tgt_src_dir) && ./configure --prefix=/usr
	$(MAKE) --directory=$(tgt_src_dir)
	$(MAKE) --directory=$(tgt_src_dir) install
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"

squashfs-tools.chroot: glibc.chroot zlib.chroot
	$(QUIET) $(ECHO) "### Building $(@)"
	$(call chroot_only)
	$(MAKE) --directory=$(tgt_src_dir)/squashfs-tools clean
	$(MAKE) --directory=$(tgt_src_dir)/squashfs-tools unsquashfs \
	EXTRA_LDFLAGS="-static"
	$(INSTALL) -D $(tgt_src_dir)/squashfs-tools/unsquashfs \
	$(chroot_build)/initramfs/usr/bin/unsquashfs
	$(MAKE) --directory=$(tgt_src_dir)/squashfs-tools clean
	$(MAKE) --directory=$(tgt_src_dir)/squashfs-tools
	$(MAKE) --directory=$(tgt_src_dir)/squashfs-tools install \
	INSTALL_DIR="/usr/bin"
	$(TOUCH) $(@)
	$(QUIET) $(ECHO) "### Done $(@)"


# post_chroot - Unmount and cleanup after leaving the chroot environment.
.PHONY: post_chroot
post_chroot:
	$(call check_if_root)
	$(QUIET) $(UMOUNT) -vl $(CHROOT_DIR)/run
	$(QUIET) $(UMOUNT) -vl $(CHROOT_DIR)/sys
	$(QUIET) $(UMOUNT) -vl $(CHROOT_DIR)/proc
	$(QUIET) $(UMOUNT) -vl $(CHROOT_DIR)/dev/pts
	$(QUIET) $(UMOUNT) -vl $(CHROOT_DIR)/dev/shm
	$(QUIET) $(UMOUNT) -vl $(CHROOT_DIR)/dev


# image - Create the ESOS disk image file.
.PHONY: image
image: loop_dev = $$($(CAT) $(WORK_DIR)/loop_dev)
image:
	$(call no_chroot)
	$(call check_if_root)
	$(QUIET) if [ -f "$(WORK_DIR)/loop_dev" ]; then \
	  $(ECHO) "### Cleaning up any remnants from a previous run..."; \
	  if $(MOUNT) | $(GREP) $(MOUNT_DIR)/boot > /dev/null; then \
	    $(UMOUNT) -v $(MOUNT_DIR)/boot; \
	  fi; \
	  if $(MOUNT) | $(GREP) $(MOUNT_DIR) > /dev/null; then \
	    $(UMOUNT) -v $(MOUNT_DIR); \
	  fi; \
	  if $(LOSETUP) $(loop_dev) > /dev/null 2>&1; then \
	    $(KPARTX) -v -d $(loop_dev); \
	    $(LOSETUP) -v -d $(loop_dev); \
	  fi; \
	  $(RM) -v $(BUILD_DIR)/esos_*.img; \
	  $(RM) -v $(BUILD_DIR)/esos_*.bz2; \
	  $(RM) -v $(BUILD_DIR)/dist_*.txt; \
	fi
	$(QUIET) $(ECHO) "### Creating initramfs image..."
	$(RM) $(INITRAMFS_DIR)/dev/*
	$(MKNOD) $(INITRAMFS_DIR)/dev/null c 1 3
	$(MKNOD) $(INITRAMFS_DIR)/dev/console c 5 1
	$(MKNOD) $(INITRAMFS_DIR)/dev/tty c 5 0
	$(QUIET) if [ "x$(enable_debug)" != "xyes" ]; then \
	  $(SED) 's/@@root_size@@/1792m/' $(SRC_DIR)/misc/initramfs_init > \
	  $(INITRAMFS_DIR)/init; \
	else \
	  $(SED) 's/@@root_size@@/2816m/' $(SRC_DIR)/misc/initramfs_init > \
	  $(INITRAMFS_DIR)/init; \
	fi
	$(CHMOD) +x $(INITRAMFS_DIR)/init
	$(LN) busybox $(INITRAMFS_DIR)/bin/sh
	$(CP) -Rp $(CHROOT_DIR)/lib/firmware/* $(INITRAMFS_DIR)/lib/firmware/
	$(CP) -Rp $(chroot_build)/initramfs/* $(INITRAMFS_DIR)/
	cd $(INITRAMFS_DIR) && $(FIND) . -print0 | \
	$(CPIO) --null -ov --format=newc | \
	$(GZIP) > $(CHROOT_DIR)/boot/PRIMARY-initramfs.cpio.gz
	$(QUIET) $(ECHO) && $(ECHO)
	$(QUIET) $(ECHO) "### Setting up the ESOS image file ($(img_file))..."
	# 4000 MB (not MiB)
	# 4000000000 B
	# 4000000000 B / 512 B = 7812500 sectors
	$(DD) if=/dev/zero of=$(img_file) bs=512 count=0 seek=7812500
	$(ECHO) -e "2048,819200,EF,*\n821248,4096000,L\n4917248,409600,L\n\
	5326848,2048000,L\n" | $(SFDISK) --no-reread -uS -L $(img_file)
	$(LOSETUP) -f --show $(img_file) > $(WORK_DIR)/loop_dev
	$(KPARTX) -a -s $(loop_dev)
	$(SLEEP) 1
	$(MKFS_VFAT) -F 32 -n ESOS_BOOT $$($(ECHO) $(loop_dev) | \
	$(SED) 's/^\/dev/\/dev\/mapper/')p1
	$(MKFS_EXT2) -L esos_root $$($(ECHO) $(loop_dev) | \
	$(SED) 's/^\/dev/\/dev\/mapper/')p2
	$(MKFS_EXT2) -L esos_conf $$($(ECHO) $(loop_dev) | \
	$(SED) 's/^\/dev/\/dev\/mapper/')p3
	$(MKFS_EXT2) -L esos_logs $$($(ECHO) $(loop_dev) | \
	$(SED) 's/^\/dev/\/dev\/mapper/')p4
	$(QUIET) $(ECHO) && $(ECHO)
	$(QUIET) $(ECHO) "### Installing image (staging)..."
	$(MOUNT) $$($(ECHO) $(loop_dev) | \
	$(SED) 's/^\/dev/\/dev\/mapper/')p2 $(MOUNT_DIR) 
	$(MKDIR) $(MOUNT_DIR)/boot
	$(MOUNT) $$($(ECHO) $(loop_dev) | \
	$(SED) 's/^\/dev/\/dev\/mapper/')p1 $(MOUNT_DIR)/boot
	cd $(CHROOT_DIR) && $(FIND) ./boot -depth | \
	$(CPIO) -pmdvu $(MOUNT_DIR)
	cd $(CHROOT_DIR) && \
	$(FIND) . -depth ! -path "./usr/include*" ! -path "*.a" \
	! -path "*.la" ! -path "./usr/share/doc*" ! -path "./usr/share/xml*" \
	! -path "./boot*" ! -path "./build*" ! -path "./sources*" \
	! -path "./tools*" ! -path "./usr/lib/pkgconfig*" \
	! -path "./usr/lib/gcc" ! -path "./usr/lib/cmake*" \
	! -path "./bin/cat" ! -path "./bin/echo" ! -path "./bin/ln" \
	! -path "./bin/pwd" ! -path "./bin/rm" ! -path "./bin/stty" \
	! -path "./bin/sh" ! -path "./usr/bin/install" \
	! -path "./usr/bin/env" ! -path "./etc/resolv.conf" | \
	$(CPIO) -pmdvu $(STAGING_DIR)
	$(INSTALL) -D $(wildcard $(CHROOT_DIR)/usr/include/python*/pyconfig.h) \
	$(STAGING_DIR)/usr/include/$(notdir \
	$(wildcard $(CHROOT_DIR)/usr/include/python*))/pyconfig.h
	$(MKDIR) $(STAGING_DIR)/usr/share/doc/esos
	$(CP) $(SRC_DIR)/COPYING $(STAGING_DIR)/usr/share/doc/esos/LICENSE
	$(INSTALL) -m 0644 $(SRC_DIR)/ChangeLog \
	$(STAGING_DIR)/usr/share/doc/esos/ChangeLog
	cd $(SRC_DIR)/etc && $(FIND) . -depth ! -path "*/.git*" | \
	$(CPIO) -pmdvu $(STAGING_DIR)/etc
	$(chroot_build)/grub-install \
	--directory=$(CHROOT_DIR)/usr/lib/grub/i386-pc \
	--grub-setup=$(chroot_build)/grub-bios-setup \
	--grub-mkimage=$(chroot_build)/grub-mkimage \
	--grub-mkrelpath=$(chroot_build)/grub-mkrelpath \
	--grub-probe=$(chroot_build)/grub-probe \
	--root-directory=$(MOUNT_DIR) --debug --no-floppy $(loop_dev)
	$(chroot_build)/grub-install \
	--directory=$(CHROOT_DIR)/usr/lib/grub/x86_64-efi \
	--grub-setup=$(chroot_build)/grub-bios-setup \
	--grub-mkimage=$(chroot_build)/grub-mkimage \
	--grub-mkrelpath=$(chroot_build)/grub-mkrelpath \
	--grub-probe=$(chroot_build)/grub-probe \
	--efi-directory=$(MOUNT_DIR)/boot --root-directory=$(MOUNT_DIR) \
	--no-nvram --removable --recheck --debug
	$(SED) 's/@@short_prod@@/$(short_prod)/g' $(SRC_DIR)/misc/grub.cfg > \
	$(MOUNT_DIR)/boot/grub/grub.cfg
	$(ECHO) "set slot_ver=$(esos_ver)" > $(MOUNT_DIR)/boot/PRIMARY-version
	$(INSTALL) $(SRC_DIR)/scripts/conf_sync.sh \
	$(STAGING_DIR)/usr/local/sbin/
	$(INSTALL) $(SRC_DIR)/scripts/usb_sync.sh \
	$(STAGING_DIR)/usr/local/sbin/
	$(INSTALL) $(SRC_DIR)/scripts/archive_logs.sh \
	$(STAGING_DIR)/usr/local/sbin/
	$(INSTALL) $(SRC_DIR)/scripts/startup.sh \
	$(STAGING_DIR)/usr/local/sbin/
	$(INSTALL) $(SRC_DIR)/scripts/health_chk.sh \
	$(STAGING_DIR)/usr/local/sbin/
	$(INSTALL) $(SRC_DIR)/scripts/crm_mon_email.sh \
	$(STAGING_DIR)/usr/local/bin/
	$(INSTALL) $(SRC_DIR)/scripts/hw_raid_cli.py \
	$(STAGING_DIR)/usr/local/sbin/
	$(INSTALL) $(SRC_DIR)/scripts/support_pkg.sh \
	$(STAGING_DIR)/usr/local/sbin/
	$(INSTALL) $(SRC_DIR)/scripts/raid_tools.py \
	$(STAGING_DIR)/usr/local/sbin/
	$(INSTALL) $(SRC_DIR)/scripts/iso_installer.sh \
	$(STAGING_DIR)/usr/local/sbin/
	$(INSTALL) $(SRC_DIR)/scripts/boot_raid1.sh \
	$(STAGING_DIR)/usr/local/sbin/
	$(INSTALL) $(SRC_DIR)/scripts/backup_conf.sh \
	$(STAGING_DIR)/usr/local/sbin/
	$(INSTALL) $(SRC_DIR)/scripts/sbd_*.sh \
	$(STAGING_DIR)/usr/local/sbin/
	$(INSTALL) $(SRC_DIR)/scripts/cluster_*.sh \
	$(STAGING_DIR)/usr/local/sbin/
	$(MKDIR) $(STAGING_DIR)/usr/lib/ocf/resource.d
	$(CP) -R $(SRC_DIR)/misc/ocf/esos \
	$(STAGING_DIR)/usr/lib/ocf/resource.d/
	$(CP) -R $(SRC_DIR)/misc/ocf/brick \
	$(STAGING_DIR)/usr/lib/ocf/resource.d/
	$(CP) -R $(SRC_DIR)/misc/ocf/onesty \
	$(STAGING_DIR)/usr/lib/ocf/resource.d/
	$(CP) -R $(SRC_DIR)/misc/ocf/stmf-ha \
	$(STAGING_DIR)/usr/lib/ocf/resource.d/
	$(INSTALL) -D -m 0755 $(SRC_DIR)/misc/drbd_xsltproc/drbd-xmlproc \
	$(STAGING_DIR)/usr/local/bin/drbd-xmlproc
	$(INSTALL) -D -m 0644 $(SRC_DIR)/misc/drbd_xsltproc/xml2conf.xsl \
	$(STAGING_DIR)/usr/local/share/drbd/xml2conf.xsl
	$(INSTALL) -m 0755 $(SRC_DIR)/contrib/check_zpools.sh \
	$(STAGING_DIR)/usr/libexec/
	$(INSTALL) -m 0755 $(SRC_DIR)/contrib/list-pcie-ports.sh \
	$(STAGING_DIR)/usr/sbin/
	$(INSTALL) -m 0644 $(SRC_DIR)/contrib/50-rbd.rules \
	$(STAGING_DIR)/usr/lib/udev/rules.d/
	$(INSTALL) -m 0755 $(SRC_DIR)/contrib/ceph-rbdnamer \
	$(STAGING_DIR)/usr/bin/
	$(LN) libncursesw.so $(STAGING_DIR)/usr/lib/libncurses.so.5
	$(ECHO) "$(product) $(esos_ver)" > \
	$(STAGING_DIR)/etc/esos-release
	$(CHOWN) -R root:root $(STAGING_DIR)/*
	$(FIND) $(STAGING_DIR)/etc -type f -print0 | $(XARGS) -0 $(CHMOD) 0644
	$(FIND) $(STAGING_DIR)/etc -type d -print0 | $(XARGS) -0 $(CHMOD) 0755
	$(FIND) $(STAGING_DIR)/etc/rc.d -type f -print0 | \
	$(XARGS) -0 $(CHMOD) 0755
	$(FIND) $(STAGING_DIR)/etc/vmware-tools -type f -print0 | \
	$(XARGS) -0 $(CHMOD) 0755
	$(FIND) $(STAGING_DIR)/etc/acpi -type f -print0 | \
	$(XARGS) -0 $(CHMOD) 0755
	$(FIND) $(STAGING_DIR)/etc/etckeeper/*.d -type f ! -path "*/README" \
	-print0 | $(XARGS) -0 $(CHMOD) 0755
	$(CHMOD) 4750 $(STAGING_DIR)/usr/local/bin/esos_tui
	$(CHMOD) 4750 $(STAGING_DIR)/usr/local/bin/esos_tui
	$(CHMOD) 4755 $(STAGING_DIR)/usr/bin/sudo
	$(CHMOD) 640 $(STAGING_DIR)/etc/shadow
	$(CHOWN) 0:42 $(STAGING_DIR)/etc/shadow
	$(CHMOD) 600 $(STAGING_DIR)/etc/crontab
	$(CHMOD) 1777 $(STAGING_DIR)/tmp
	$(CHMOD) 1777 $(STAGING_DIR)/var/tmp
	$(CHMOD) 755 $(STAGING_DIR)/root
	$(CHMOD) 700 $(STAGING_DIR)/root/.ssh
	$(QUIET) if [ "$(enable_mhvtl)" = "yes" ]; then \
	  $(CHMOD) 4750 $(STAGING_DIR)/usr/bin/vtltape; \
	  $(CHMOD) 4750 $(STAGING_DIR)/usr/bin/vtllibrary; \
	fi
	$(QUIET) if [ "$(enable_login_tui)" = "no" ]; then \
	  $(TOUCH) $(STAGING_DIR)/var/state/esos/no_login_tui; \
	fi
	$(QUIET) if [ "$(enable_auto_dhcp)" = "yes" ]; then \
	  $(TOUCH) $(STAGING_DIR)/var/state/esos/auto_dhcp; \
	fi
	$(CHOWN) 101:101 $(STAGING_DIR)/var/lib/corosync
	$(CHOWN) -R 101:101 $(STAGING_DIR)/var/lib/pacemaker
	$(CHOWN) -R 101:101 $(STAGING_DIR)/var/lib/heartbeat
	$(CHOWN) 101:101 $(STAGING_DIR)/var/run/crm
	$(CHOWN) 65534:65534 $(STAGING_DIR)/var/run/stunnel
	$(CHOWN) 0:65534 $(STAGING_DIR)/var/lib/stunnel
	$(CHMOD) 1770 $(STAGING_DIR)/var/lib/stunnel
	$(LN) rc.0 $(STAGING_DIR)/etc/rc.d/rc.6
	$(LN) rc.2 $(STAGING_DIR)/etc/rc.d/rc.5
	$(LN) rc.2 $(STAGING_DIR)/etc/rc.d/rc.4
	$(LN) rc.2 $(STAGING_DIR)/etc/rc.d/rc.3
	$(MKDIR) $(STAGING_DIR)/boot
	$(FIND) $(STAGING_DIR)/etc -path $(STAGING_DIR)/etc/rc.d -prune -o \
	-print0 | $(XARGS) -0 $(TOUCH) -h -d "2001-01-01 00:00:00"
	$(FIND) $(STAGING_DIR)/var/lib -print0 | \
	$(XARGS) -0 $(TOUCH) -h -d "2001-01-01 00:00:00"
	$(SED) -i 's/ $(subst /,\/,$(CHROOT_DIR))\// \//g' \
	$(STAGING_DIR)/usr/lib/libc.so
	$(SED) -i 's/ $(subst /,\/,$(CHROOT_DIR))\// \//g' \
	$(STAGING_DIR)/usr/lib/libpthread.so
	cd $(STAGING_DIR)/usr/share/man && \
	$(FIND) . -type l ! -path "*.gz" -exec \
	sh -c '$(LN) `$(READLINK) $$1`.gz $$1.gz && $(RM) $$1' _ {} \;
	cd $(STAGING_DIR)/usr/share/man && \
	$(FIND) . -type f ! -path "*.gz" -exec $(GZIP) {} \;
	$(QUIET) if [ "x$(enable_debug)" != "xyes" ]; then \
	  $(FIND) $(STAGING_DIR)/{,usr/}{lib,bin,sbin} -type f \
	  -executable -exec $(STRIP) --strip-debug '{}' ';'; \
	fi
	$(QUIET) if [ "$(with_customize_dir)" = "yes" ]; then \
	  if [ -x "$(customize_dir)/inject.sh" ]; then \
	    $(customize_dir)/inject.sh $(STAGING_DIR); \
	  fi; \
	fi
	$(QUIET) $(ECHO) && $(ECHO)
	$(QUIET) $(ECHO) "### Creating the root archive file..."
	$(MKSQUASHFS) $(STAGING_DIR) $(MOUNT_DIR)/PRIMARY-root.sqsh -comp gzip
	$(CHOWN) -R root:root $(MOUNT_DIR)/boot/*
	$(UMOUNT) $(MOUNT_DIR)/boot
	$(UMOUNT) $(MOUNT_DIR)
	$(KPARTX) -d $(loop_dev)
	$(LOSETUP) -d $(loop_dev)
	$(LN) $(img_file) $(stable_img_file)
	$(QUIET) $(ECHO) && $(ECHO)
	$(QUIET) $(ECHO) "### Compressing image file..."
	$(BZIP2) -z -9 -c $(img_file) > $(bz2_img_file)
	cd $(dir $(bz2_img_file)) && $(MD5SUM) -b \
	$(notdir $(bz2_img_file)) > $(BUILD_DIR)/dist_md5sum.txt
	cd $(dir $(bz2_img_file)) && $(SHA256SUM) -b \
	$(notdir $(bz2_img_file)) > $(BUILD_DIR)/dist_sha256sum.txt
	$(QUIET) $(ECHO) && $(ECHO)
	$(QUIET) $(ECHO) "### Clearing the staging directory..."
	$(RM) $(STAGING_DIR)
	$(MKDIR) $(STAGING_DIR)
	$(QUIET) $(ECHO) && $(ECHO)
	$(QUIET) $(ECHO) "### All done; your ESOS disk image file is ready!"


# pkg_dist - Create the ESOS package distribution file (tarball).
.PHONY: pkg_dist
pkg_dist: pkg_prefix = $(pkg_name)-$(esos_ver)
pkg_dist: $(bz2_img_file)
	$(call no_chroot)
	$(ECHO) "$(product) $(esos_ver)" > $(BUILD_DIR)/VERSION
	$(RM) $(BUILD_DIR)/ChangeLog-*.txt
	$(RM) $(BUILD_DIR)/esos_*.zip
	$(LN) $(SRC_DIR)/ChangeLog $(BUILD_DIR)/ChangeLog-$(esos_ver).txt
	$(LN) $(BUILD_DIR) $(pkg_prefix)
	$(ZIP) -9 $(pkg_prefix).zip $(pkg_prefix)/$(notdir $(bz2_img_file)) \
	$(pkg_prefix)/dist_*.txt
	$(RM) $(pkg_prefix)
	$(LN) $(SRC_DIR) $(pkg_prefix)
	$(ZIP) -9 -g $(pkg_prefix).zip $(pkg_prefix)/ChangeLog \
	$(pkg_prefix)/install.sh $(pkg_prefix)/install.vbs \
	$(pkg_prefix)/INSTALL $(pkg_prefix)/README $(pkg_prefix)/COPYING \
	$(pkg_prefix)/VERSION
	$(RM) $(pkg_prefix)
	$(LN) $(wildcard $(SOURCES_DIR)/win_binaries-*) $(pkg_prefix)
	$(ZIP) -9 -g -r $(pkg_prefix).zip $(pkg_prefix)/*
	$(RM) $(pkg_prefix)
	$(LN) $(chroot_build) $(pkg_prefix)
	$(ZIP) -9 -g -r $(pkg_prefix).zip $(pkg_prefix)/vmlinux*.xz
	$(ZIP) -9 -g -r $(pkg_prefix).zip $(pkg_prefix)/System.map*.xz
	$(RM) $(pkg_prefix)

